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",
    id="coding-agent",
    model=Claude(id="claude-sonnet-4-20250514"),
    tools=[daytona_tools],
    markdown=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
sandbox_idstrNoneExisting sandbox ID to connect to
sandbox_languageCodeLanguageCodeLanguage.PYTHONThe programming language to run on the sandbox
sandbox_targetstrNoneThe target configuration for sandbox creation
sandbox_osstrNoneThe operating system to run on the sandbox
auto_stop_intervalint60Stop sandbox after this many minutes of inactivity
sandbox_os_userstrNoneThe user to run the sandbox as
sandbox_env_varsDict[str, str]NoneEnvironment variables to set in the sandbox
sandbox_labelsDict[str, str]NoneLabels to set on the sandbox
sandbox_publicboolNoneWhether the sandbox should be public
organization_idstrNoneThe organization ID to use for the sandbox
timeoutint300Timeout in seconds for communication with the sandbox
auto_create_sandboxboolTrueWhether to automatically create a sandbox if none exists
verify_sslboolFalseWhether to verify SSL certificates
persistentboolTrueWhether the sandbox should persist between requests
instructionsstrNoneCustom instructions for using the Daytona tools
add_instructionsboolFalseWhether to add default instructions

Code Execution Tools

FunctionDescription
run_python_codeRun Python code in the contextual Daytona sandbox
run_codeRun non-Python code in the contextual Daytona sandbox
You can use include_tools or exclude_tools to modify the list of tools the agent has access to. Learn more about selecting tools.

Developer Resources