Skip to content

Daytona Documentation

View as Markdown

Daytona is an open-source, secure and elastic infrastructure for running AI-generated code.

Daytona provides isolated sandbox environments that you can manage programmatically using the Daytona SDK to run and control code execution.

Daytona SDK is available for Python and TypeScript interfaces.

Create an account

Open the Daytona Dashboard ↗ and create your account. Daytona supports account creation using an email and password, or by connecting your Google or GitHub account.

Obtain an API key

Generate an API key from the Daytona Dashboard ↗ to authenticate SDK requests and access Daytona services. Save the API key securely, as it won’t be shown again.

Install the SDK

Install the Daytona SDK to interact with sandboxes from your code using Python or TypeScript.

Terminal window
pip install daytona

Create a Sandbox

Create a Daytona Sandbox to run your code securely in an isolated environment.

# Import the Daytona SDK
from daytona import Daytona, DaytonaConfig
# Define the configuration
config = DaytonaConfig(api_key="YOUR_API_KEY") # Replace with your API key
# Initialize the Daytona client
daytona = Daytona(config)
# Create the Sandbox instance
sandbox = daytona.create()

Write code

Create a program that runs code inside a Daytona Sandbox. The following snippet is an example “Hello World” program that runs securely inside a Daytona Sandbox.

main.py

# Import the Daytona SDK
from daytona import Daytona, DaytonaConfig
# Define the configuration
config = DaytonaConfig(api_key="YOUR_API_KEY") # Replace with your API key
# Initialize the Daytona client
daytona = Daytona(config)
# Create the Sandbox instance
sandbox = daytona.create()
# Run the code securely inside the Sandbox
response = sandbox.process.code_run('print("Hello World")')
# Check the response
if response.exit_code != 0:
print(f"Error: {response.exit_code} {response.result}")
else:
print(response.result)
# Clean up
sandbox.delete()

Run code

Run the program to execute your code in a secure and isolated Daytona Sandbox environment.

Terminal window
python main.py
Hello World

Summary

By following the steps above, you successfully create a Daytona account, obtain an API key, install the SDK, create a sandbox, write code, and run it securely in a Daytona Sandbox.

Introduction

Account management

Agent Toolbox

Computer Use

Other

Guides

Deployments