Code Execution Agents

Authors 6 articles 68 min total read

This topic is curated by our AI council — see how it works.

Most agentic capabilities in this theme connect the model to an existing system — a database, a browser, an API. Code execution agents connect it to a computer: the model writes a script, runs it, reads the output, and decides what to do next. That closed loop is why they anchor the core agent loop alongside planning and multi-agent work — a plan is only as good as what actually executes it, and here the model is both planner and executor. For a developer, the interesting part isn’t that the model can write code; it’s what has to exist underneath before that code is safe to run.

  • Code execution agents outperform JSON-based tool calling on many tasks because the model chains several operations in one script instead of round-tripping through an LLM call for every step.
  • Safety is a sandbox problem before it’s a model problem — production agents need hardware-level isolation like Firecracker or gVisor microVMs, not just a container.
  • The Claude Agent SDK’s built-in Bash tool runs in your own process, not a sandbox — treat it as a development convenience, never expose it to model-written code in production.
  • Benchmark leaderboards now move on scaffold changes as much as model upgrades, so evaluate the harness wrapped around the model, not just the model itself.

The code execution agent reading path: mechanism, limits, then the build

Start with how sandboxed interpreters let LLMs run their own code — it explains why letting the model write and execute Python inside a container often beats structured tool calling, and what a minimal stack looks like. Then read the prerequisites, from ReAct loops to microVM isolation: it lays out the three layers — reasoning loop, sandbox runtime, hardware isolation — that have to exist before any of this is safe, which is what separates a toy demo from a defensible security posture.

Before you build anything, the honest limits read is worth the ten minutes: cold-start latency, flaky benchmark tests, and shrinking effective context are structural, not vendor-specific, so budget for them rather than debug around them later. When you’re ready to wire one up, the E2B, Daytona, and Claude Agent SDK guide specifies the sandbox contract — lifecycle, network rules, timeouts — before a single line of tool code. For the market context behind that choice, the 2026 SWE-bench race coverage shows why the harness wrapped around a model now moves benchmark scores more than swapping the model itself. Close with the accountability question — if your agent will ever touch production credentials, read it before you ship, not after.

MONA asks: 'If the agent can just call a Python interpreter, why do teams spend weeks on microVM isolation?' MAX answers: 'Because that interpreter runs code the model wrote, not code you reviewed — skip the hardware boundary and one bad script reaches your host.' — comic dialog.
The interpreter is trusted software; the code running inside it is not.

How code execution agents differ from tool calling, frameworks, and retrieval

Three neighbours get folded into this topic, and each mix-up sends the design in the wrong direction.

  • Code execution is not JSON tool calling. Classic tool use has the model emit a structured call, wait for a round trip, then decide again — one LLM turn per step. A code execution agent writes a script that chains several operations itself, calling the model only when it needs a new decision. The gain is fewer round trips; the cost is a much bigger blast radius per turn, which is exactly what the sandbox layer exists to contain.
  • The sandbox is not the agent framework. Agent frameworks like LangGraph or CrewAI decide how steps are sequenced and which tool gets called next; the sandbox is what actually executes the code once the framework hands it off. Swapping frameworks doesn’t change your isolation posture, and hardening the sandbox doesn’t fix a broken control flow — they’re separate contracts.
  • Running code is not retrieving knowledge. Retrieval-augmented agents decide when and what to search for; code execution agents decide when and what to run. Some production systems need both loops side by side — a retrieval decision to find the right data, then a code decision to transform it — and conflating the two is a common source of unpredictable latency.

Common questions about code execution agents

Q: How is a code execution agent different from a tool-calling agent that returns JSON? A: A tool-calling agent emits one structured call per LLM turn and waits for the result before deciding again. A code execution agent writes a script that chains several operations in one pass, calling the model only when a new decision is needed — fewer round trips, but more damage per turn if the sandbox isn’t isolated. See how sandboxed interpreters let LLMs run their own code.

Q: Is the Claude Agent SDK’s built-in Bash tool safe to use in production? A: No — it runs inside your own process, not a sandbox, so model-written code executes with your process’s own permissions. Use it for local development only; in production, replace it with a custom tool that routes execution through E2B or Daytona, as the build guide specifies.

Q: Do I need microVM isolation, or is a container sandbox enough? A: It depends on what the model is allowed to do: a standard container shares the host kernel, fine for trusted, narrow tasks, but model-written code is untrusted by definition. The prerequisites read covers why production stacks add a hardware-level boundary like Firecracker or gVisor underneath.

Q: Should I evaluate a code execution agent by its base model or by its scaffold? A: By the scaffold first. The same underlying model can post very different SWE-bench results depending on the harness wrapped around it, so a leaderboard comparison across vendors is really a comparison of engineering, not just model quality. The 2026 SWE-bench race breaks down what shifted.

Q: Who is accountable when a code execution agent breaks something in production? A: Legally and organizationally, nobody has fully answered that yet — the credentials were authorized, but not for the specific action the agent took. The accountability piece traces a real incident where an agent deleted a production database during a declared code freeze.

Part of the AI agent architecture theme · closest neighbour: agent planning and reasoning. Coming to sandboxed execution from a software background? Start with the story: Debugging Agents: Reconstruct the Decision Path, Not a Stack Trace.

1

Understand the Fundamentals

Code execution agents close the loop between writing code and seeing what it does. Understanding their ReAct cycles, sandbox primitives, and failure modes is the foundation for everything else.

2

Build with Code Execution Agents

Practical guides walk through wiring a code agent to a real sandbox provider, handling state between runs, and shipping it without burning your laptop or your cloud bill.

4

Risks and Considerations

When an LLM runs code it wrote, accountability gets blurry. Supply-chain attacks, data exfiltration, and silent failures all change shape, and so do the questions you should ask before deploying.