Traditional AI agents interact with the world through rigid interfaces—predefined JSON schemas, specific API calls, or structured text commands. While functional, these "tool-use" paradigms often struggle with complex logic, multi-step reasoning, and unforeseen edge cases. A growing body of research suggests a more powerful alternative: treating executable code as the primary action space for Large Language Models (LLMs).
The Shift from Tool-Use to Code-Action
In the standard "ReAct" or tool-calling framework, an agent selects a tool from a fixed list and provides arguments in a structured format. However, as Xingyao Wang and colleagues argue in Executable Code Actions Elicit Better LLM Agents, this limits the agent's expressive power. Their framework, CodeAct, allows agents to emit Python code directly.
The intuition is simple: Python is a Turing-complete language that inherently handles control flow, data manipulation, and error handling. Instead of an agent trying to coordinate five different JSON calls to process a dataset, it can write a single script that loops through the data, performs calculations, and handles exceptions. This approach has been shown to improve task success rates by up to 20% by reducing the "communication overhead" between the model's reasoning and the environment's execution.
The REPL as a Reasoning Engine
When an agent uses code as an action, the Python interpreter (or REPL) becomes more than just a tool; it becomes a feedback mechanism for the model's internal "thoughts." This is the core of "execution-based" verification.
In LEVER: Learning to Verify Language-to-Code Generation with Execution, Ansong Ni demonstrates that models can significantly improve their accuracy by sampling multiple code candidates and selecting the one that executes successfully and produces plausible results. Similarly, the AgentCoder framework AgentCoder: Multi-Agent-based Code Generation with Iterative Testing and Optimisation uses a multi-agent system where one agent writes code, another designs tests, and a third executes them. This iterative loop allows the agent to "debug" its own reasoning before finalizing an answer.
From Using Tools to Making Tools
If an agent can execute code, it can also create its own capabilities. This moves the field from static agents to "self-evolving" systems.
- Tool Making: Tianle Cai and Xinyun Chen introduced the LATM (LLMs As Tool Makers) framework Large Language Models As Tool Makers, where a powerful model like GPT-4 writes a reusable Python function (a "tool") for a specific task, which a smaller, cheaper model then uses to solve future instances of that problem.
- Skill Induction: Zora Zhiruo Wang and Apurva Gandhi developed Agent Skill Induction (ASI) Inducing Programmatic Skills for Agentic Tasks, which allows web agents to bootstrap their own libraries of executable functions for common tasks like "login" or "search," making them more efficient over time.
- Dynamic Action Spaces: The DynaSaur framework DynaSaur: Large Language Agents Beyond Predefined Actions enables agents to break free from fixed toolsets entirely by generating and accumulating custom Python functions to handle unforeseen edge cases.
The Sandbox Imperative
The primary barrier to deploying these agents is safety. Granting an LLM the power to execute arbitrary code is inherently dangerous. As Graham Neubig and Daniel Fried highlight in their work on the ODEX benchmark Execution-Based Evaluation for Open-Domain Code Generation, real-world library usage introduces significant security risks, including the potential for malicious system calls or data loss.
To mitigate this, researchers emphasize the use of isolated sandbox environments (like Docker containers or specialized runtimes). Platforms like OpenHands OpenHands: An Open Platform for AI Software Developers as Generalist Agents provide these secure environments where agents can write and test code without compromising the host system.
However, even with sandboxing, ethical concerns remain. Margaret Mitchell and Avijit Ghosh argue in Fully Autonomous AI Agents Should Not be Developed that the ability for agents to self-modify through code execution represents a critical threshold where human-defined guardrails can be systematically bypassed, necessitating a shift toward "human-in-the-loop" or declarative programming models like PDL PDL: A Declarative Prompt Programming Language.