Skip to content

Daytona Documentation

View as Markdown

Daytona is an open-source, secure and elastic infrastructure for running AI-generated code. Daytona provides full composable computers — sandboxes — that you can manage programmatically using the Daytona SDKs, CLI, and API to run and control code execution.

Daytona SDK is available for Python, TypeScript, Ruby and Go interfaces.

1. Create an account

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

2. Obtain an API key

Generate an API key from the Daytona Dashboard ↗ or using the Daytona API to authenticate SDK requests and access Daytona services.

3. Install the SDK

Install the Daytona Python, TypeScript, Ruby or Go SDKs to interact with sandboxes from code.

Terminal window
pip install daytona

4. Create a Sandbox

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

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()

5. Write and run code

Create a program that runs code inside a sandbox. The following snippets are examples of “Hello World” programs that run securely inside a 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()

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 sandbox.

Next steps

Use the following resources to interact with sandboxes: