Daytona offers secure and elastic infrastructure for runnning 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 Daytona tools require the daytona_sdk Python package:

pip install daytona_sdk

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

export DAYTONA_API_KEY=your_api_key

Example

The following example demonstrates how to create an agent that can run Python code in a Daytona sandbox:

cookbook/tools/daytona_tools.py
from agno.agent import Agent
from agno.models.anthropic import Claude
from agno.tools.daytona import DaytonaTools

daytona_tools = DaytonaTools()

# Setup an Agent focused on coding tasks, with access to the Daytona tools
agent = Agent(
    name="Coding Agent with Daytona tools",
    agent_id="coding-agent",
    model=Claude(id="claude-sonnet-4-20250514"),
    tools=[daytona_tools],
    markdown=True,
    show_tool_calls=True,
    instructions=[
        "You are an expert at writing and validating Python code. You have access to a remote, secure Daytona sandbox.",
        "Your primary purpose is to:",
        "1. Write clear, efficient Python code based on user requests",
        "2. Execute and verify the code in the Daytona sandbox",
        "3. Share the complete code with the user, as this is the main use case",
        "4. Provide thorough explanations of how the code works",
        "You can use the run_python_code tool to run Python code in the Daytona sandbox.",
        "Guidelines:",
        "- ALWAYS share the complete code with the user, properly formatted in code blocks",
        "- Verify code functionality by executing it in the sandbox before sharing",
        "- Iterate and debug code as needed to ensure it works correctly",
        "- Use pandas, matplotlib, and other Python libraries for data analysis when appropriate",
        "- Create proper visualizations when requested and add them as image artifacts to show inline",
        "- Handle file uploads and downloads properly",
        "- Explain your approach and the code's functionality in detail",
        "- Format responses with both code and explanations for maximum clarity",
        "- Handle errors gracefully and explain any issues encountered",
    ],
)

# Example: Generate Fibonacci numbers
agent.print_response(
    "Write Python code to generate the first 10 Fibonacci numbers and calculate their sum and average"
)

Toolkit Params

ParameterTypeDefaultDescription
api_keystrNoneDaytona API key. If not provided, uses DAYTONA_API_KEY env var.
api_urlstrNoneDaytona API URL. If not provided, uses DAYTONA_API_URL env var or the Daytona default.
sandbox_languageCodeLanguagePythonThe programming language to run on the sandbox
sandbox_target_regionstrNoneThe region where the sandbox will be created
sandbox_osstrNoneThe operating system to run on the sandbox (default: ubuntu)
sandbox_os_userstrNoneThe user to run the sandbox as (default: root)
sandbox_env_varsdictNoneThe environment variables to set in the sandbox
sandbox_labelsdictNoneThe labels to set in the sandbox
sandbox_publicboolNoneWhether the sandbox should be public
sandbox_auto_stop_intervalintNoneThe interval in seconds at which the sandbox will be automatically stopped
organization_idstrNoneThe organization ID to use for the sandbox
timeoutint300Timeout in seconds for communication with the sandbox (default: 5 minutes)

Code Execution Tools

FunctionDescription
run_python_codeRun Python code in the contextual Daytona sandbox
run_codeRun non-Python code in the contextual Daytona sandbox

Developer Resources