> ## Documentation Index
> Fetch the complete documentation index at: https://docs.upsonic.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# CodeExecutionTool

> A built-in tool that allows models to execute code in a sandboxed environment

## Overview

A built-in tool that allows models to execute code in a sandboxed environment.

## Usage

```python theme={null}
from upsonic import Agent, Task
from upsonic.tools.builtin_tools import CodeExecutionTool
from upsonic.models.openai import OpenAIResponsesModel

# Create model
model = OpenAIResponsesModel(
    model_name="gpt-4o",
    provider="openai"
)

# Create code execution tool
code_exec = CodeExecutionTool()

# Create task
task = Task(
    description="Write a Python function to calculate factorial and test it with 5",
    tools=[code_exec]
)

# Create agent
agent = Agent(model=model, name="Code Execution Agent")

# Execute
result = agent.print_do(task)
print("Result:", result)
```

## Advanced Example

```python theme={null}
from upsonic.tools.builtin_tools import CodeExecutionTool
from upsonic.models.openai import OpenAIResponsesModel
from upsonic import Agent, Task


model = OpenAIResponsesModel(
    model_name="gpt-4o",
    provider="openai"
)

code_exec = CodeExecutionTool()

# Complex computation task
task = Task(
    description="""
    Write and execute Python code to:
    1. Calculate Fibonacci sequence up to 10 terms
    2. Find prime numbers up to 50
    3. Create a simple data visualization (if matplotlib available)
    """,
    tools=[code_exec]
)

agent = Agent(model=model, name="Computational Agent")
result = agent.print_do(task)
print("Result:", result)
```

## Parameters

* No configuration parameters (provider-managed execution)

## Provider Support

* Anthropic: ✅ Full support
* OpenAI Responses: ✅ Full support
* Google: ✅ Full support

## Characteristics

* Sandboxed execution environment
* Python code support
* Provider-managed security and isolation
* Automatic timeout and resource limits
