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

# Daytona

> Enable your Agents to run code in a remote, secure sandbox.

**Daytona** offers secure and elastic infrastructure for running your AI-generated code. At Agno, we integrate with it to enable your Agents and Teams to run code in your Daytona sandboxes.

## Prerequisites

The following example requires the `daytona` and `openai` packages:

```shell theme={null}
uv pip install daytona openai
```

You will also need a Daytona API key. You can get it from your [Daytona dashboard](https://app.daytona.io/dashboard/keys):

```shell theme={null}
export DAYTONA_API_KEY=your_api_key
```

## Example

This example creates an agent that can run code in a Daytona sandbox:

```python cookbook/91_tools/daytona_tools.py theme={null}
from agno.agent import Agent
from agno.tools.daytona import DaytonaTools

agent = Agent(
    name="Coding Agent with Daytona tools",
    tools=[DaytonaTools()],
    markdown=True,
    instructions=[
        "You are an expert at writing and executing code. You have access to a remote, secure Daytona sandbox.",
        "Your primary purpose is to:",
        "1. Write clear, efficient code based on user requests",
        "2. ALWAYS execute the code in the Daytona sandbox using run_code",
        "3. Show the actual execution results to the user",
        "4. Provide explanations of how the code works and what the output means",
        "Guidelines:",
        "- NEVER just provide code without executing it",
        "- Execute all code using the run_code tool to show real results",
        "- Support Python, JavaScript, and TypeScript execution",
        "- Use file operations (create_file, read_file) when working with scripts",
        "- Install missing packages when needed using run_shell_command",
        "- Always show both the code AND the execution output",
        "- Handle errors gracefully and explain any issues encountered",
    ],
)

agent.print_response(
    "Write JavaScript code to generate 10 random numbers between 1 and 100, sort them in ascending order, and print each number"
)
```

## Toolkit Params

| Parameter | Type | Default | Description |
| - | - | - | - |
| `api_key` | `Optional[str]` | `None` | Daytona API key. If not provided, uses DAYTONA\_API\_KEY env var |
| `api_url` | `Optional[str]` | `None` | Daytona API URL. If not provided, uses DAYTONA\_API\_URL env var |
| `sandbox_id` | `Optional[str]` | `None` | Existing sandbox ID to connect to |
| `sandbox_language` | `Optional[CodeLanguage]` | `None` | The programming language to run on the sandbox. Defaults to Python when not set |
| `sandbox_target` | `Optional[str]` | `None` | The target configuration for sandbox creation |
| `sandbox_os` | `Optional[str]` | `None` | The operating system to run on the sandbox |
| `auto_stop_interval` | `Optional[int]` | `60` | Stop sandbox after this many minutes of inactivity |
| `sandbox_os_user` | `Optional[str]` | `None` | The user to run the sandbox as |
| `sandbox_env_vars` | `Optional[Dict[str, str]]` | `None` | Environment variables to set in the sandbox |
| `sandbox_labels` | `Optional[Dict[str, str]]` | `None` | Labels to set on the sandbox |
| `sandbox_public` | `Optional[bool]` | `None` | Whether the sandbox should be public |
| `organization_id` | `Optional[str]` | `None` | The organization ID to use for the sandbox |
| `timeout` | `int` | `300` | Timeout in seconds for communication with the sandbox |
| `auto_create_sandbox` | `bool` | `True` | Fall back to creating a fresh sandbox when sandbox management errors. When `False`, the error is raised. A sandbox is always created when none exists |
| `verify_ssl` | `Optional[bool]` | `False` | Whether to verify SSL certificates |
| `persistent` | `bool` | `True` | Whether the sandbox should persist between requests |
| `instructions` | `Optional[str]` | `None` | Custom instructions for using the Daytona tools |
| `add_instructions` | `bool` | `False` | Whether to add default instructions |

## Toolkit Functions

| Function | Description |
| - | - |
| `run_code` | Execute code in the Daytona sandbox (language set by `sandbox_language`) |
| `run_shell_command` | Execute a shell command in the sandbox |
| `create_file` | Create or update a file in the sandbox |
| `read_file` | Read a file from the sandbox |
| `list_files` | List files in a directory |
| `delete_file` | Delete a file or directory from the sandbox |
| `change_directory` | Change the current working directory |

You can use `include_tools` or `exclude_tools` to modify the list of tools the agent has access to. Learn more about [selecting tools](https://agno-v2.mintlify.site/tools/selecting-tools.md).

## Developer Resources

* [Tools](https://github.com/agno-agi/agno/blob/main/libs/agno/agno/tools/daytona.py)
* [Daytona Documentation](https://www.daytona.io/docs/)


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