Skip to main content
code_execution.py
code_execution_20250825 is generally available and does not need a beta header. It gives Claude Bash, file operations, and Python through the sandbox. During streaming, tool input can arrive incrementally, but each execution-result block arrives as a complete block.
Anthropic offers code execution on the Claude API, Claude Platform on AWS, and Hosted-on-Anthropic Microsoft Foundry deployments. It is unavailable on Amazon Bedrock and Google Cloud.
Code execution is not eligible for Zero Data Retention. Anthropic retains container data, including uploaded files and execution output, for up to 30 days. Files created in the Files API remain until they are deleted.
See Anthropic’s code-execution documentation for model compatibility, runtime limits, pricing, and retention details.

Run the Example

1

Set up your virtual environment

2

Install dependencies

3

Set your API key

4

Save and run

Save the example as code_execution.py, then run: