Daytona
Enable your Agents to run code in a remote, secure sandbox.
Daytona offers secure and elastic infrastructure for runnning your AI-generated code. At Kern, 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:
1uv pip install daytona_sdkYou will also need a Daytona API key. You can get it from your Daytona account:
1export DAYTONA_API_KEY=your_api_keyExample
The following example demonstrates how to create an agent that can run Python code in a Daytona sandbox:
1from kern.agent import Agent2from kern.models.anthropic import Claude3from kern.tools.daytona import DaytonaTools45daytona_tools = DaytonaTools()67# Setup an Agent focused on coding tasks, with access to the Daytona tools8agent = Agent(9 name="Coding Agent with Daytona tools",10 id="coding-agent",11 model=Claude(id="claude-sonnet-4-20250514"),12 tools=[daytona_tools],13 markdown=True,14 instructions=[15 "You are an expert at writing and validating Python code. You have access to a remote, secure Daytona sandbox.",16 "Your primary purpose is to:",17 "1. Write clear, efficient Python code based on user requests",18 "2. Execute and verify the code in the Daytona sandbox",19 "3. Share the complete code with the user, as this is the main use case",20 "4. Provide thorough explanations of how the code works",21 "You can use the run_python_code tool to run Python code in the Daytona sandbox.",22 "Guidelines:",23 "- ALWAYS share the complete code with the user, properly formatted in code blocks",24 "- Verify code functionality by executing it in the sandbox before sharing",25 "- Iterate and debug code as needed to ensure it works correctly",26 "- Use pandas, matplotlib, and other Python libraries for data analysis when appropriate",27 "- Create proper visualizations when requested and add them as image artifacts to show inline",28 "- Handle file uploads and downloads properly",29 "- Explain your approach and the code's functionality in detail",30 "- Format responses with both code and explanations for maximum clarity",31 "- Handle errors gracefully and explain any issues encountered",32 ],33)3435# Example: Generate Fibonacci numbers36agent.print_response(37 "Write Python code to generate the first 10 Fibonacci numbers and calculate their sum and average"38)Toolkit Params
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | str | None | Daytona API key. If not provided, uses DAYTONA_API_KEY env var |
api_url | str | None | Daytona API URL. If not provided, uses DAYTONA_API_URL env var |
sandbox_id | str | None | Existing sandbox ID to connect to |
sandbox_language | CodeLanguage | CodeLanguage.PYTHON | The programming language to run on the sandbox |
sandbox_target | str | None | The target configuration for sandbox creation |
sandbox_os | str | None | The operating system to run on the sandbox |
auto_stop_interval | int | 60 | Stop sandbox after this many minutes of inactivity |
sandbox_os_user | str | None | The user to run the sandbox as |
sandbox_env_vars | Dict[str, str] | None | Environment variables to set in the sandbox |
sandbox_labels | Dict[str, str] | None | Labels to set on the sandbox |
sandbox_public | bool | None | Whether the sandbox should be public |
organization_id | 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 | Whether to automatically create a sandbox if none exists |
verify_ssl | bool | False | Whether to verify SSL certificates |
persistent | bool | True | Whether the sandbox should persist between requests |
instructions | str | None | Custom instructions for using the Daytona tools |
add_instructions | bool | False | Whether to add default instructions |
Code Execution Tools
| Function | Description |
|---|---|
run_python_code | Run Python code in the contextual Daytona sandbox |
run_code | Run 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
- View Tools
- View Daytona Documentation