loading
loading
A server-side tool that runs the model's code in an Anthropic-hosted sandbox — you declare it and the model executes code with no client-side loop.
Declare {type: "code_execution_20260120", name: "code_execution"} in tools and the model gets a sandboxed Python 3.11 container (with pandas, matplotlib, openpyxl, etc.) plus bash and file sub-tools, all running on Anthropic's infrastructure. Results come back as content blocks in the same response — check bash_code_execution_tool_result for stdout and return code. Containers persist and can be reused across requests to keep state. It powers data analysis, file/report generation, and the dynamic filtering behind newer web-search tools — and it's the substrate for programmatic tool calling, where the model writes a script that calls your tools and only the final result hits its context.
Plainly
Think of Code Execution as a tool from the builder toolbox. A server-side tool that runs the model's code in an Anthropic-hosted sandbox — you declare it and the model executes code with no client-side loop.
In practice
Use it when you are installing, editing, testing, reviewing, or shipping code. In practice, define the owner, input, output, and failure mode before you rely on it.