> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Code Execution Tool

> Run Python and Bash in Anthropic's server-side sandbox from an Agno agent.

```python code_execution.py theme={null}
from agno.agent import Agent
from agno.models.anthropic import Claude

agent = Agent(
    model=Claude(id="claude-sonnet-4-5-20250929"),
    tools=[
        {
            "type": "code_execution_20250825",
            "name": "code_execution",
        }
    ],
    markdown=True,
)

if __name__ == "__main__":
    agent.print_response(
        "Use the code execution tool to calculate the mean and standard deviation of "
        "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10].",
        stream=True,
    )
```

`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.

> [!NOTE]
>
> 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.

> [!WARNING]
>
> 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](https://platform.claude.com/docs/en/agents-and-tools/tool-use/code-execution-tool) for model compatibility, runtime limits, pricing, and retention details.

## Run the Example

<Snippet file="create-venv-step.mdx" />

**1. Install dependencies**

```bash theme={null}
uv pip install -U "agno[anthropic]"
```

**2. Set your API key**

```bash Mac/Linux theme={null}
export ANTHROPIC_API_KEY="your_anthropic_api_key"
```

```powershell Windows theme={null}
$Env:ANTHROPIC_API_KEY="your_anthropic_api_key"
```

**3. Save and run**

Save the example as `code_execution.py`, then run:

```bash theme={null}
python code_execution.py
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.