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):

  1. With web search or web fetch 20260209 or later in the request: code execution is free; you pay only tokens.
  2. 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

Moments

Why we built-and donated-the Model Context Protocol (MCP)

Anthropic

  1. With code_execution_20260120 or later, Claude can write a Python script that calls your own tools from inside the…

See also

About this page

Last updated Nov 6, 2026 by the Vi.ki team. Page text CC BY-SA 4.0.

Edit History

Hotkeys

/
Jump to the search box
? or Ctrl + /
Open this list
Esc
Close this list, the photo viewer, or the account menu

Video

Space or K
Play or pause
← →
Back or forward 5 seconds
J L
Back or forward 10 seconds
0 to 9
Go to 0% to 90% of the video
, .
Previous or next frame, while paused
M
Mute or unmute
C
Captions on or off
F
Full screen on or off
A D
Previous or next moment

Photo viewer

← → or A D
Previous or next photo
↑ ↓ or W S
Previous or next photo
Home End
First or last photo
I
Show or hide the photo's info
Z
Clickless on or off: a pointer over a thumbnail shows it
N
Compare with the last photo: back to the one shown before this, and N again comes back
Q
Move the thumbnails to the next edge: top, bottom, left and round
, or Ctrl + ,
Open or close the viewer's settings
V
Clickless pan: a zoomed photo follows the pointer, rather than being dragged
Shift
Browse on or off
B
Show or hide the button bar
T
Show or hide the thumbnails
1
100% zoom on or off
0
Rate the photo as no opinion; again takes the answer back
+ -
Rate the photo a step higher or lower
F
Full screen: the photo alone. F again puts everything back.
Back to top