Code Execution Tool
The Claude API's code execution tool runs Bash commands and Python in a sandboxed Linux container at Anthropic, with 5 GiB of memory and no internet access. Each organization gets 1,550 free container hours a month, then $0.05 per hour, and it is free when used with the newer web search or web fetch tools.
The code execution tool gives Claude a sandboxed Linux container at Anthropic where it can run Bash commands, write and edit files, and run Python 3.11 with common data libraries, all inside one Claude API request. Every organization gets 1,550 free container hours a month, then pays $0.05 per container hour, and code execution costs nothing extra when the request also uses web search or web fetch version 20260209 or later (as of Nov 6, 2026). It is a server tool: the API runs the commands and feeds the output back to Claude, so your code sends no tool results.
Do not confuse it with Claude Code, Anthropic's coding agent: this is a tool inside the API. For making files in the Claude apps, see File Creation.
Quick facts
| Tool versions | code_execution_20250825 (Bash and files), code_execution_20260120 (adds REPL state and programmatic tool calling), code_execution_20260521 (same runtime, tells Claude about the 90-second cell limit); no beta header (Code execution tool) |
| Runtime | Python 3.11, Linux, x86_64 |
| Resources | 5 GiB RAM, 5 GiB workspace disk, 1 CPU |
| Network | None: "Completely disabled", so no package installs at runtime |
| Container life | Expires 30 days after creation; checkpointed after about 5 minutes idle |
| Price | 1,550 free hours a month per organization, then $0.05 per container hour, minimum 5 minutes per use |
| Zero data retention | Not eligible: container data is kept up to 30 days |
How do you use the code execution tool?
Add it to tools; its type picks the version and its name must be code_execution:
import anthropic
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-opus-5-5",
max_tokens=4096,
messages=[{
"role": "user",
"content": "Calculate the mean and standard deviation of [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]",
}],
tools=[{"type": "code_execution_20250825", "name": "code_execution"}],
)
Claude then has two sub-tools: bash_code_execution for shell commands and text_editor_code_execution to view, create and edit files. The response interleaves the commands Claude ran with their results, then Claude's answer, and includes a container object whose ID you can send back to keep working in the same container (Code execution tool).
What is installed?
The container comes with pandas, numpy, scipy, scikit-learn, statsmodels, matplotlib, seaborn, pyarrow, openpyxl, xlsxwriter, pillow, python-pptx, python-docx, pypdf, pdfplumber, reportlab, sympy and others, plus command-line tools such as ripgrep, fd, sqlite, unzip and 7zip (Code execution tool). Because there is no internet, nothing else can be installed: if a job needs another library or network access, use your own sandbox with the client-side bash tool, or a Managed Agents environment, which can preinstall packages and allow chosen hosts.
Working with files
To give Claude your data, upload it with the Files API and reference it in the message with a container_upload block and its file_id:
from pathlib import Path
file_object = client.files.upload(file=Path("data.csv"))
response = client.messages.create(
model="claude-opus-5-5",
max_tokens=4096,
messages=[{"role": "user", "content": [
{"type": "text", "text": "Analyze this CSV data"},
{"type": "container_upload", "file_id": file_object.id},
]}],
tools=[{"type": "code_execution_20250825", "name": "code_execution"}],
)
Files Claude creates come back as file_id entries, but only those written to the top level of the $OUTPUT_DIR folder each Bash call gets; anything saved elsewhere stays in the container. Download them with client.files.download(file_id). Images, video and audio downloaded this way carry C2PA Content Credentials naming Anthropic as the issuer (Code execution tool). Note that including files in a request bills container time even if Claude never runs code, because the files are loaded into the container first.
Skills in containers
Agent Skills run on top of code execution. In the Messages API you list skill_ids in the container parameter and include the code execution tool; Anthropic's prebuilt skills (pptx, xlsx, docx, pdf) are how Claude makes office files through the API, and custom skills upload through /v1/skills. A request can carry up to 20 skills (Using Agent Skills with the API). Skills left beta on the Claude API on Aug 19, 2026. See How to Build a Claude Skill.
Programmatic tool calling
With code_execution_20260120 or later, Claude can write a Python script that calls your own tools from inside the container, instead of one model round trip per call. Anthropic's example: checking budgets for 20 employees becomes one script rather than 20 round trips (Programmatic tool calling). You opt each tool in with allowed_callers. Each Python cell has a 90-second wall-clock limit, and Claude Haiku 4.5 does not support the feature. This is also what powers dynamic filtering in the Web Search and Web Fetch Tools.
How much does it cost?
There are two cases (Pricing):
- With web search or web fetch
20260209or later in the request: code execution is free; you pay only tokens. - Otherwise: billed by container time, at least 5 minutes per use, with 1,550 free hours per organization each month and $0.05 per container hour after that.
Inside Managed Agents, the $0.08 session-hour fee replaces container billing. See Claude API Pricing.
Limits and gotchas
- Two computers. If you also give Claude a client-side bash tool, it now has two separate machines and can confuse them; the docs supply a system prompt paragraph that tells Claude state is not shared (Code execution tool).
- Platforms. Claude API, Claude Platform on AWS, Claude Models on Google Cloud (Anthropic managed) and Microsoft Foundry hosted on Anthropic. Not Amazon Bedrock, not Google managed, and not Foundry deployments hosted on Azure (Claude in Microsoft Foundry). See Claude on Cloud Platforms.
- Privacy. Container data, uploads and outputs are kept up to 30 days, so the tool is outside zero data retention and HIPAA; see Claude Privacy and Data Use.
- History. The tool launched in beta on May 22, 2025 with Python only; Bash and file handling came with version 2 on Sep 2, 2025.
Frequently asked questions
Is the Claude code execution tool free? Partly. Each organization gets 1,550 free hours of Claude code execution a month and pays $0.05 per container hour beyond that, and code execution is free whenever the request also includes web search or web fetch version 20260209 or later (as of Nov 6, 2026).
Can Claude's code execution sandbox access the internet? No. The Claude code execution container has internet access completely disabled, so it cannot download data or install packages; send data in with the Files API instead.
What languages does the Claude code execution tool run? The Claude code execution tool runs Bash commands and Python 3.11 in a Linux container, with data libraries such as pandas, numpy and matplotlib preinstalled.
How long does a Claude code execution container last? A Claude code execution container expires 30 days after it is created; it is checkpointed after about 5 minutes idle and restored when you send its ID again.
Is the Claude code execution tool the same as Claude Code? No. The code execution tool is a sandbox inside the Claude API, while Claude Code is Anthropic's coding agent that works on your own files and terminal.
Sources
- Why we built-and donated-the Model Context Protocol (MCP), Anthropic, Dec 11, 2025 (video)
- Code execution tool, Anthropic docs, read Nov 6, 2026
- Programmatic tool calling, Anthropic docs, read Nov 6, 2026
- Using Agent Skills with the API, Anthropic docs, read Nov 6, 2026
- Pricing, Anthropic docs, read Nov 6, 2026
- Claude in Microsoft Foundry, Anthropic docs, read Nov 6, 2026
- Release notes, Anthropic docs, read Nov 6, 2026
Moments
Why we built-and donated-the Model Context Protocol (MCP)
Anthropic
See also
-
Claude APIThe Claude API is Anthropic's REST API at api.anthropic.com for building with Claude models: create an API key in the Claude Console at platform.claude.com, then send requests to the Messages API, paying per token.
-
Claude CodeClaude Code is Anthropic's agentic coding tool. It reads a codebase, edits files, runs commands and opens pull requests from the terminal, VS Code, JetBrains IDEs, the Claude desktop app, the browser and Slack, and it comes with every paid Claude plan or a pay-as-you-go Console account. -
File CreationClaude can create and edit Excel spreadsheets, PowerPoint decks, Word documents and PDFs that you download or save to Google Drive, on every Claude plan including Free. It writes and runs code in a private sandbox to build them.
-
Managed AgentsClaude Managed Agents is Anthropic's hosted agent service: you define an agent once, and Anthropic runs its loop, tools and sandbox for each session, billing normal token prices plus $0.08 per session-hour of running time. It has been in beta on the Claude API since Apr 8, 2026. - Files APIThe Claude Files API stores a PDF, text file, image or dataset once with POST /v1/files and returns a file_id that later Claude API requests reference instead of re-uploading. Files up to 500 MB, 1 TB per organization, free to store; out of beta since Aug 19, 2026.
-
SkillsA Claude skill is a folder with a SKILL.md file of instructions, plus optional scripts and files, that Claude loads when a task needs it. Skills are on every Claude plan, Free included, and the same skill runs in the Claude app, Claude Code and the API.