Code execution as an agent's action
For engineers
Agents that write and run code instead of one tool call per turn: programmatic tool calling, code mode, sandboxes and risks
110 questions across four stages: Understand, Apply, Solve and Judge.
Try 5 questions
Practice items, not counted towards your mastery. No account needed.
Check yourself · 1 of 5
An agent must check 120 order IDs against a shipping API. Why is one script usually better than 120 separate tool-call turns?
Check yourself · 2 of 5
What does programmatic tool calling change about how a model uses your tools?
Check yourself · 3 of 5
An agent will run generated Python on a customer's uploaded file. Which network setting is the safest default?
Check yourself · 4 of 5
What is wrong with wrapping every call in an agent's script in try/except and doing nothing on error?
Check yourself · 5 of 5
Which task is the weakest fit for a code action?
Topics
- Why code beats one call per turn4 min read · Loops, filtering and composing tools in code to cut model round trips and keep large intermediate data out of context
- Programmatic tool calling and code mode5 min read · Exposing tools as typed functions the model calls from a script, as in Claude programmatic tool calling, Cloudflare Code Mode and smolagents
- Sandboxing agent-written code5 min read · Containers, microVMs and hosted code-execution tools with filesystem, network, time and memory limits
- Failure modes of code-acting agents5 min read · Swallowed exceptions, partial outputs, data exfiltration through code and generated scripts nobody reviews
Start here
- Executable Code Actions Elicit Better LLM Agents (CodeAct) (opens in a new tab)PaperFree
The research paper behind code as an agent's action, compared with JSON tool calls.
- Code execution with MCP (Anthropic) (opens in a new tab)ArticleFree
How code actions cut tool-definition and result tokens, and what sandboxing they need.
- Programmatic tool calling (Claude API docs) (opens in a new tab)DocsFree
How Claude calls your tools from code it writes, and what the host must provide.
Helps to know first
110 questions · last verified 2026-12