22One agent

Code actions

The agent writes code that calls its tools, and an interpreter runs it and returns the result.

Also called CodeAct, Code Mode, Code execution with MCP

Wang et al., Anthropic, Cloudflare, Hugging Face

coderesultAgentAgentToolInterpreterToolTools
How to read this

The problem

Tool calls written as JSON cannot be combined, and every intermediate result passes through the model.

LLM agents are typically prompted to produce actions by generating JSON or text in a pre-defined format, which is usually limited by constrained action space (e.g., the scope of pre-defined tools) and restricted flexibility (e.g., inability to compose multiple tools).
Wang et al.Executable Code Actions Elicit Better LLM Agents
Every intermediate result must pass through the model.
AnthropicCode execution with MCP: Building more efficient agentsNov 4, 2025

Therefore

Integrated with a Python interpreter, CodeAct can execute code actions and dynamically revise prior actions or emit new actions upon new observations through multi-turn interactions.
Wang et al.Executable Code Actions Elicit Better LLM Agents
With code execution environments becoming more common for agents, a solution is to present MCP servers as code APIs rather than direct tool calls.
AnthropicCode execution with MCP: Building more efficient agentsNov 4, 2025
Multiple research papers have shown that having the LLMs actions written as code snippets is a more natural and flexible way of writing them.
Hugging FaceWhat are agents?

In use

Cloudflare Agents SDK

Instead of being presented with all the tools of all the connected MCP servers, our agent is presented with just one tool, which simply executes some TypeScript code.
CloudflareCode Mode: the better way to use MCPSep 26, 2025

Where it breaks

Running model-written code needs a sandbox, resource limits and monitoring that direct tool calls avoid.

Running agent-generated code requires a secure execution environment with appropriate sandboxing, resource limits, and monitoring. These infrastructure requirements add operational overhead and security considerations that direct tool calls avoid.
AnthropicCode execution with MCP: Building more efficient agentsNov 4, 2025

Sources

  1. Executable Code Actions Elicit Better LLM AgentsWang et al.
  2. Code execution with MCP: Building more efficient agentsAnthropic, Nov 4, 2025
    Code execution with MCP enables agents to use context more efficiently by loading tools on demand, filtering data before it reaches the model, and executing complex logic in a single step.
  3. Code Mode: the better way to use MCPKenton Varda and Sunil Pai, Cloudflare, Sep 26, 2025
    When you connect to an MCP server in "code mode", the Agents SDK will fetch the MCP server's schema, and then convert it into a TypeScript API, complete with doc comments based on the schema.
  4. What are agents?Hugging Face

Added Nov 14, 2026