In short.
This guide explains Claude's hosted code execution for developers building data analysis and file generation workflows, with no internet access in the runtime and container data retained for up to 30 days. It documents server-side execution, file retrieval, container reuse and version compatibility. The documented design suits workloads that fit the installed libraries and small container limits. Execution charges depend on the tools included in the request, while model token charges remain. The feature is ineligible for zero data retention and HIPAA use. Correctness, latency and reliability were not assessed.
Researched and written by an AI model and checked by a second AI model. How it works
The evidence covers the complete selected documentation page at [https://platform.claude.com/docs/en/agents-and-tools/tool-use/code-execution-tool.md], including its version, availability, billing, file-capture, Content Credentials and data-retention notices. Linked pages are excluded, so their additional API details, service terms and licensing provisions are unknown. No commands, SDK examples or API requests were executed; performance, security properties, generated outputs and actual charges remain untested.
The overview
Identity
This resource is Anthropic's Code execution tool documentation. It teaches developers to configure a hosted Claude capability through the Messages API, upload inputs and retrieve generated files. The original source is [https://platform.claude.com/docs/en/agents-and-tools/tool-use/code-execution-tool.md].
Assessment
Based on its documented design, the tool is a useful candidate for assistants that calculate results, analyze uploaded spreadsheets or generate charts and documents without a developer maintaining the execution environment. The guide provides integration details covering requests, responses, errors and file delivery.
Fit depends on whether the workload can operate without network access, additional packages or substantial computing resources. Data retention also needs attention: container data can remain for up to 30 days, while generated Files API files persist until explicitly deleted.
Users
The audience is developers building Claude applications that process data or create files. Beginners get calculation and upload examples; experienced developers get response formats, streaming behavior, container lifecycle details and migration guidance.
Applying the guide requires familiarity with API credentials, structured messages and response parsing. Its examples cover cURL, the Anthropic CLI and several programming-language SDKs.
Capabilities
Claude can run Bash commands, write and execute Python, create or edit files, perform calculations and produce visualizations. Documented inputs include CSV, Excel, JSON, XML, images and text. Installed libraries include pandas, NumPy, SciPy, scikit-learn, matplotlib, spreadsheet readers and PDF-processing tools.
Files can persist between requests when the application reuses a container. Newer tool versions also support programmatic tool calling and persistent Python interpreter state on supported models.
On the Claude API, supported generated image, video and audio files downloaded through the Files API receive C2PA Content Credentials. Signing changes metadata, file size and checksum without changing visible content. Text files, PDFs and office documents are not signed.
Using it
Requirements
An integration needs API access, credentials and a supported model on a documented platform. The page lists the Claude API, Claude Platform on AWS, Anthropic-managed Claude Models on Google Cloud and Anthropic-hosted Microsoft Foundry. Claude Mythos Preview has a narrower stated availability: Claude API and Microsoft Foundry.
The documented model-support check is capabilities.server_tools.code_execution.supported in the Models API. The separate capabilities.code_execution field concerns programmatic tool calling. Claude Haiku 4.5 accepts newer execution tool versions but does not support programmatic tool calling or the associated persistent Python state.
Mechanism
Claude decides whether computation or file handling would help, then invokes bash_code_execution or text_editor_code_execution. The API runs these operations server-side and normally returns results within the same request. Responses interleave server_tool_use blocks, tool results and Claude's text, with container information at the top level.
Version code_execution_20250825 provides Bash and file operations. Version code_execution_20260120 adds programmatic tool calling and persistent Python state. Version code_execution_20260521 uses the same runtime as code_execution_20260120 but tells Claude about the 90-second wall-clock limit on each programmatic Python cell.
When client-provided tools are called alongside code execution, the execution result can arrive in a later response after the application supplies its client-tool results. Streaming delivers tool inputs incrementally and each result block whole.
Setup
Add a tool named code_execution to a Messages API request and select its type. The latest version named on the page is code_execution_20260521; no anthropic-beta header is required. The quick-start examples use code_execution_20250825, model claude-opus-5-5 and API version 2026-10-21. Programmatic tool calling, persistent Python state and the documented newer web search or web fetch integrations require code_execution_20260120 or later.
Upload input files through the Files API and reference their IDs in container_upload message blocks. For deliverables, ask Claude to copy files into the top level of $OUTPUT_DIR and list that directory in the same command. The application retrieves the returned file IDs through the Files API.
Pass the response's container ID into subsequent requests to preserve files. Include it when continuing a pause_turn response. An expired container cannot be restored; retry without its ID to create a new one.
Example
The documented CSV workflow uploads data.csv, places the returned file_id in a container_upload block, asks Claude to analyze the CSV and enables code execution. A separate example requests a matplotlib visualization saved as output.png.
Combining these documented patterns, an application could request a chart from an uploaded CSV, have Claude place the image in $OUTPUT_DIR, then download the file IDs returned in bash_code_execution_result. This is an illustrative integration sequence; no API calls were executed and no generated chart or analysis result was assessed.
Assessment & evidence
Limitations
The documented runtime is Python 3.11 on Linux x86_64, with one CPU, 5 GiB of RAM and 5 GiB of workspace storage. Outbound networking is disabled, and additional packages cannot be downloaded or installed at runtime. Workloads must use the installed libraries.
Each programmatic Python cell has a 90-second wall-clock limit. A cell timeout produces a non-zero return_code and detection_timeout message; a whole-tool timeout uses execution_time_exceeded. The page does not specify the whole-tool time limit or numeric output-size threshold.
Containers expire 30 days after creation and may be checkpointed after about five minutes of inactivity. The response's rolling expires_at value does not express the full 30-day limit. Only files placed at the top level of each command's $OUTPUT_DIR are returned as downloadable artifacts.
Container data is retained for up to 30 days, and generated Files API files persist until explicitly deleted. The feature is marked ineligible for zero data retention and HIPAA use. When combined with a client-side shell or custom interpreter, files and variables are not shared between environments, and the page warns that Claude can confuse them.
Reasoning
The documented design suggests less execution infrastructure for the application developer: Anthropic runs the hosted commands and returns their results. Integration work remains around response parsing, container IDs, file downloads, deletion and failures.
Running code can supply computational evidence for an answer, but successful execution alone does not establish that Claude chose the correct formula, interpreted the data correctly or generated a valid report. Applications should inspect return_code and stderr and validate important outputs. Accuracy and reliability remain unassessed.
Alternatives
The page describes client-provided Bash tools and custom interpreters as execution environments controlled by the application developer. It recommends those tools when access to the user's local system, files or data is needed. Using both approaches requires explicit separation of their state and responsibilities.
Claude can also answer simple arithmetic or factual requests without executing code. For borderline tasks where computation matters, the page recommends explicitly asking it to run code. No competing vendor products, comparative benchmarks or alternative hosting costs are established here.
Evidence
The evidence is Anthropic's complete Code execution tool documentation at [https://platform.claude.com/docs/en/agents-and-tools/tool-use/code-execution-tool.md]. It supplies request examples, response structures, compatibility guidance, resource limits, pricing and data-handling notices.
These are vendor documentation claims. The page supplies no independent performance measurements or demonstrated workload results. Runtime behavior, security isolation, output quality and billing accuracy were not tested.
Access & freshness
Costs
The page states that code execution has no additional execution charge when the request includes web_search_20260209, web_fetch_20260209 or a later version of either tool. Standard input and output token charges remain.
Without those tools, execution-time billing has a five-minute minimum. Each organization receives 1,550 free execution hours per month; additional usage is quoted at $0.05 USD per hour, per container. Including files incurs execution-time billing even when Claude does not call the tool, because the files are preloaded.
Execution through the Messages Batches API uses the same execution pricing. The page does not supply model token rates, a complete application cost estimate or actual charges for any workload. Those costs remain unknown.
Rights
The page does not provide a redistribution license for the documentation, service licensing terms or output-ownership terms. Commercial-use and redistribution rights are not established by this evidence.
Content Credentials on supported generated media identify Anthropic as the signing issuer and record a timestamp and action description. The page states that these credentials contain no information about the user, organization or request. They do not establish ownership rights.
Freshness
The documentation was captured on 14 November 2026 at 22:07:37.224 UTC. It labels the feature stable and identifies code_execution_20260521 as the latest tool version. Publication and last-update dates are unknown.
Model availability, installed dependencies and pricing reflect that documentation snapshot. Their current service state has not been independently confirmed. The page advises checking compatibility when adopting a newer model.
Actions
Before adoption, confirm the chosen model's server-side code execution support, required libraries and compatibility with the documented resource limits. Check whether container retention and separate deletion of generated Files API files fit the application's data requirements.
Evaluate a representative calculation or uploaded-file task for result correctness, response parsing, output capture and container reuse. Include timeout handling and any interaction with client-provided tools. Establish model token rates and expected execution usage before estimating total cost; these evaluations have not been performed.
