Follow Discord
Sweep 31 Oct 2026 · 01:10Z Build v2.1.316 534 read Stable v2.1.309 Latest v2.1.316 Next v2.1.316 Feeds RSS JSON llms.txt llms-full.txt Unofficial
One change · api

code-execution-tool changedagents-and-tools/tool-use/code-execution-tool

Recorded here
Lines+43added
Lines−15removed
From line 4 where the diff opens
First seen 14 Aug 2026 this site's first read of the page
Recorded edits27to this page, all time

## Availability ### API support #### [Messages API](https://platform.claude.com/docs/en/build-with-claude/working-with-messages) ### Data handling

The whole hunk

from line 4, old and new numbered
/
lines
from line 4
44description: Run Python and Bash code in a sandboxed container to analyze data, generate files, and iterate on solutions.
55featureMetadata:
66 status: ga
7 zdr: not-eligible
7 zdr:
8 eligibility: not-eligible
9 note: Container data retained up to 30 days.
810 supportedModels:
911 - claude-fable-5-1
1012 - claude-mythos-5-1
1113 - claude-fable-5
1214 - claude-mythos-5
15 - claude-mythos-preview
1316 - claude-opus-5-5
1417 - claude-opus-5
18 - claude-sonnet-5-5
19 - claude-sonnet-5
20 - claude-haiku-5-5
21 - claude-haiku-4-5-20251001
1522 - claude-opus-4-8
1623 - claude-opus-4-7
1724 - claude-opus-4-6
18 - claude-opus-4-5-20251101
19 - claude-sonnet-5-5
20 - claude-sonnet-5
2125 - claude-sonnet-4-6
26 - claude-opus-4-5-20251101
2227 - claude-sonnet-4-5-20250929
23 - claude-haiku-5-5
24 - claude-haiku-4-5-20251001
2528 supportedPlatforms:
2629 Claude API: ga
2730 Claude Platform on AWS: ga
28 Microsoft Foundry:
29 availability: ga
30 note: On [Microsoft Foundry](https://platform.claude.com/docs/en/build-with-claude/claude-in-microsoft-foundry), code execution requires a [Hosted on Anthropic deployment](https://platform.claude.com/docs/en/build-with-claude/claude-in-microsoft-foundry#additional-features-not-supported-when-hosted-on-azure).
31 Claude Models on Google Cloud (Anthropic managed): ga
32 Microsoft Foundry (hosted on Anthropic): ga
3133 details:
3234 - Every supported model accepts all three [tool versions](https://platform.claude.com/docs/en/agents-and-tools/tool-use/code-execution-tool#tool-versions). On Claude Haiku 4.5, programmatic tool calling and REPL state persistence aren't available, so the newer versions behave like `code_execution_20250825` there.
33 - For [Claude Mythos Preview](https://anthropic.com/glasswing), code execution is supported on the Claude API and Microsoft Foundry.
3435---
3536 
3637Claude can analyze data, create visualizations, perform complex calculations, run system commands, create and edit files, and process uploaded files directly within the API conversation. The code execution tool allows Claude to run Bash commands and manipulate files, including writing code, in a secure, sandboxed environment.
from line 46
4546 
4647## Tool versions
4748 
48The code execution tool has three current versions, and every [supported model](https://platform.claude.com/docs/en/agents-and-tools/tool-use/code-execution-tool#compatibility) accepts all three. Each version builds on the previous one:
49The code execution tool has three current versions, and every [supported model](https://platform.claude.com/docs/en/agents-and-tools/tool-use/code-execution-tool#availability-feature-support) accepts all three. Each version builds on the previous one:
4950 
5051* `code_execution_20250825` supports Bash commands and file operations.
5152* `code_execution_20260120` adds REPL state persistence and [programmatic tool calling](https://platform.claude.com/docs/en/agents-and-tools/tool-use/programmatic-tool-calling) from within the sandbox. Claude Haiku 4.5 accepts the `code_execution_20260120` and `code_execution_20260521` tool types, but programmatic tool calling and the REPL state persistence that depends on it aren’t available on it, so the newer versions behave like `code_execution_20250825` there.
5253* `code_execution_20260521` is the same runtime as `code_execution_20260120`. The difference is that the tool description tells Claude about the 90-second wall-clock limit on each Python cell in programmatic tool calling, so Claude can budget long-running cells. A cell that exceeds the limit returns a normal code execution result with a non-zero `return_code` and a `detection_timeout` status message in its output. This is separate from the `execution_time_exceeded` [error code](https://platform.claude.com/docs/en/agents-and-tools/tool-use/code-execution-tool#errors), which the API returns when a whole tool call exceeds the maximum execution time.
5354 
55For [Claude Mythos Preview](https://anthropic.com/glasswing), code execution is supported on the Claude API and Microsoft Foundry.
56 
5457None of the three tool versions requires an `anthropic-beta` header. The legacy code execution beta headers remain valid opt-ins.
5558 
5659The examples on this page use `code_execution_20250825`, which covers the Bash and file operations they demonstrate and behaves the same way on every supported model; use `code_execution_20260120` or later when you need programmatic tool calling or REPL state persistence. The current [web search](https://platform.claude.com/docs/en/agents-and-tools/tool-use/web-search-tool) and [web fetch](https://platform.claude.com/docs/en/agents-and-tools/tool-use/web-fetch-tool) tools (`web_search_20260209`, `web_fetch_20260209`, and later) require `code_execution_20260120` or later as their code execution version.
5760 
58Older tool versions aren’t guaranteed to stay compatible with newer models. When you adopt a new model, check [Tool versions](https://platform.claude.com/docs/en/agents-and-tools/tool-use/code-execution-tool#tool-versions) and [Compatibility](https://platform.claude.com/docs/en/agents-and-tools/tool-use/code-execution-tool#compatibility), and prefer the newest tool version your integration supports.
61Older tool versions aren’t guaranteed to stay compatible with newer models. When you adopt a new model, check [Tool versions](https://platform.claude.com/docs/en/agents-and-tools/tool-use/code-execution-tool#tool-versions) and [API support](https://platform.claude.com/docs/en/agents-and-tools/tool-use/code-execution-tool#availability-feature-support), and prefer the newest tool version your integration supports.
5962 
6063To check whether a model accepts the code execution tool before you send a request, read its `capabilities.server_tools.code_execution.supported` value from the Models API. Don’t use the top-level `capabilities.code_execution` value for this. It reports whether code running in this tool can call your request’s other tools, as in programmatic tool calling. [Using the Models API](https://platform.claude.com/docs/en/models/overview#using-the-models-api) describes both fields.
6164 
from line 1492
14891492 
14901493## Upgrade to latest tool version
14911494 
1492The latest tool version is `code_execution_20260521`. To move between the three current versions, update the `type` string in your request: all three return the response blocks documented in [Response format](https://platform.claude.com/docs/en/agents-and-tools/tool-use/code-execution-tool#response-format). See [Tool versions](https://platform.claude.com/docs/en/agents-and-tools/tool-use/code-execution-tool#tool-versions) for what each version adds and [Compatibility](https://platform.claude.com/docs/en/agents-and-tools/tool-use/code-execution-tool#compatibility) for the models that support them.
1495The latest tool version is `code_execution_20260521`. To move between the three current versions, update the `type` string in your request: all three return the response blocks documented in [Response format](https://platform.claude.com/docs/en/agents-and-tools/tool-use/code-execution-tool#response-format). See [Tool versions](https://platform.claude.com/docs/en/agents-and-tools/tool-use/code-execution-tool#tool-versions) for what each version adds and [API support](https://platform.claude.com/docs/en/agents-and-tools/tool-use/code-execution-tool#availability-feature-support) for the models that support them.
14931496 
14941497The rest of this section covers migrating from the legacy Python-only `code_execution_20250522` to the current tool versions.
14951498 
from line 1528
15251528 
15261529Code execution runs in server-side sandbox containers. Container data, including execution artifacts, uploaded files, and outputs, is retained for up to 30 days. This retention applies to all data processed within the container environment. Files that code execution creates in the [Files API](https://platform.claude.com/docs/en/build-with-claude/files) (retrievable with `client.files.download()` (csharp, go: `client.Files.Download()`; java: `client.files().download()`; php: `$client->files->download()`)) persist until explicitly deleted.
15271530 
1528For ZDR eligibility across all features, see [API and data retention](https://platform.claude.com/docs/en/manage-claude/api-and-data-retention).
1529 
15301531## Next steps
15311532 
15321533<CardGroup cols={2}>
from line 1547
15461547 Learn how to use Agent Skills to extend Claude’s capabilities through the API.
15471548 </Card>
15481549</CardGroup>
1550 
1551## Availability
1552 
1553Code execution tool is available on every model.
1554 
1555### API support
1556 
1557#### [Messages API](https://platform.claude.com/docs/en/build-with-claude/working-with-messages)
1558 
1559* Availability: Available
1560 
1561| Status | Cloud platforms |
1562| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
1563| Available | Claude API, [Claude Platform on AWS](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws), [Claude Models on Google Cloud (Anthropic managed)](https://platform.claude.com/docs/en/build-with-claude/claude-models-on-google-cloud/anthropic-managed), [Microsoft Foundry (hosted on Anthropic)](https://platform.claude.com/docs/en/build-with-claude/claude-in-microsoft-foundry) |
1564 
1565### Data handling
1566 
1567[Data handling overview](https://platform.claude.com/docs/en/manage-claude/api-and-data-retention#feature-eligibility)
1568 
1569| Item | Zero data retention | HIPAA |
1570| ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ |
1571| Status | Not eligible | Not eligible |
1572| Details | Container data retained up to 30 days. [Learn more](https://platform.claude.com/docs/en/agents-and-tools/tool-use/code-execution-tool#data-retention) | — |
1573 
1574Applicable endpoints:
1575 
1576* `/v1/messages` with `code_execution` tool
15491577 
Feedback