> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agno.com/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.
</Note>

<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.
</Warning>

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

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

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U "agno[anthropic]"
    ```
  </Step>

  <Step title="Set your API key">
    <CodeGroup>
      ```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"
      ```
    </CodeGroup>
  </Step>

  <Step title="Save and run">
    Save the example as `code_execution.py`, then run:

    ```bash theme={null}
    python code_execution.py
    ```
  </Step>
</Steps>
