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:

uv pip install agno daytona openai

You will also need a Daytona API key. You can get it from your Daytona dashboard:

export DAYTONA_API_KEY=your_api_key

Example

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

cookbook/91_tools/daytona_tools.py
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

ParameterTypeDefaultDescription
api_keyOptional[str]NoneDaytona API key. If not provided, uses DAYTONA_API_KEY env var
api_urlOptional[str]NoneDaytona API URL. If not provided, uses DAYTONA_API_URL env var
sandbox_idOptional[str]NoneExisting sandbox ID to connect to
sandbox_languageOptional[CodeLanguage]NoneThe programming language to run on the sandbox. Defaults to Python when not set
sandbox_targetOptional[str]NoneThe target configuration for sandbox creation
sandbox_osOptional[str]NoneStored for compatibility; currently not forwarded to sandbox creation
auto_stop_intervalOptional[int]60Stop sandbox after this many minutes of inactivity
sandbox_os_userOptional[str]NoneThe user to run the sandbox as
sandbox_env_varsOptional[Dict[str, str]]NoneEnvironment variables to set in the sandbox
sandbox_labelsOptional[Dict[str, str]]NoneLabels to set on the sandbox
sandbox_publicOptional[bool]NoneWhether the sandbox should be public
organization_idOptional[str]NoneThe organization ID to use for the sandbox
timeoutint300Timeout in seconds for communication with the sandbox
auto_create_sandboxboolTrueFall 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_sslOptional[bool]FalseWhen false, patches the Daytona SDK configuration process-wide to disable certificate verification
persistentboolTrueStore the sandbox ID in agent session state for reuse; persistence across processes requires persisted session state
instructionsOptional[str]NoneCustom instructions for using the Daytona tools
add_instructionsboolFalseWhether to add default instructions

Toolkit Functions

FunctionDescription
run_codeExecute code in the Daytona sandbox (language set by sandbox_language)
run_shell_commandExecute a shell command in the sandbox
create_fileCreate or update a file in the sandbox
read_fileRead a file from the sandbox
list_filesList files in a directory
delete_fileDelete a file or directory from the sandbox
change_directoryChange 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.

Run the example with the default Python sandbox

The cookbook above requests JavaScript, but the default sandbox language is Python. For a standalone script, replace that example with:

from agno.agent import Agent
from agno.tools.daytona import DaytonaTools

agent = Agent(
    tools=[DaytonaTools(verify_ssl=True, include_tools=["run_code"])],
    instructions=["Write and execute Python using run_code, then explain the result."],
    markdown=True,
)
agent.print_response(
    "Write Python code to generate 10 random integers between 1 and 100 and print them sorted."
)

Save this as daytona_demo.py and run python daytona_demo.py. The toolkit creates a sandbox on first use and can retain its ID in session state. Stop or delete it through Daytona when finished; auto_stop_interval configures provider inactivity stopping and does not delete the sandbox.

The current create_file implementation alters single quotes in file contents. Use the provider's filesystem API for writing quoted code until that adapter path is repaired.

Developer Resources