Daytona Documentation
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.
pip install daytonanpm install @daytonaio/sdkgem install daytonago get github.com/daytonaio/daytona/libs/sdk-go4. Create a Sandbox
Create a sandbox to run your code securely in an isolated environment.
main.py
# Import the Daytona SDKfrom daytona import Daytona, DaytonaConfig
# Define the configurationconfig = DaytonaConfig(api_key="YOUR_API_KEY") # Replace with your API key
# Initialize the Daytona clientdaytona = Daytona(config)
# Create the Sandbox instancesandbox = daytona.create()index.mts
// Import the Daytona SDKimport { Daytona } from '@daytonaio/sdk'
// Initialize the Daytona clientconst daytona = new Daytona({ apiKey: 'YOUR_API_KEY' }) // Replace with your API key
// Create the Sandbox instanceconst sandbox = await daytona.create()main.rb
require 'daytona'
# Initialize the Daytona clientconfig = Daytona::Config.new(api_key: 'YOUR_API_KEY') # Replace with your API key
# Create the Daytona clientdaytona = Daytona::Daytona.new(config)
# Create the Sandbox instancesandbox = daytona.createmain.go
package main
import ( "context" "fmt"
"github.com/daytonaio/daytona/libs/sdk-go/pkg/daytona" "github.com/daytonaio/daytona/libs/sdk-go/pkg/types")
func main() { config := &types.DaytonaConfig{ APIKey: "YOUR_API_KEY", // Replace with your API key } client, _ := daytona.NewClientWithConfig(config) ctx := context.Background() sandbox, _ := client.Create(ctx, nil) fmt.Println(sandbox.ID)}curl https://app.daytona.io/api/sandbox \ --request POST \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer YOUR_API_KEY' \ --data '{}'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 SDKfrom daytona import Daytona, DaytonaConfig
# Define the configurationconfig = DaytonaConfig(api_key="YOUR_API_KEY") # Replace with your API key
# Initialize the Daytona clientdaytona = Daytona(config)
# Create the Sandbox instancesandbox = daytona.create()
# Run the code securely inside the Sandboxresponse = sandbox.process.code_run('print("Hello World")')
# Check the responseif response.exit_code != 0: print(f"Error: {response.exit_code} {response.result}")else: print(response.result)
# Clean upsandbox.delete()index.mts
// Import the Daytona SDKimport { Daytona } from '@daytonaio/sdk'
// Initialize the Daytona clientconst daytona = new Daytona({ apiKey: 'YOUR_API_KEY' }) // Replace with your API key
// Create the Sandbox instanceconst sandbox = await daytona.create({ language: 'typescript',})
// Run the code securely inside the Sandboxconst response = await sandbox.process.codeRun('console.log("Hello World")')
// Check the responseif (response.exitCode !== 0) { console.error(`Error: ${response.exitCode} ${response.result}`)} else { console.log(response.result)}
// Clean upawait sandbox.delete()main.rb
require 'daytona'
# Initialize the Daytona clientconfig = Daytona::Config.new(api_key: 'YOUR_API_KEY')daytona = Daytona::Daytona.new(config)
# Create the Sandbox instancesandbox = daytona.create
# Run the code securely inside the Sandboxresponse = sandbox.process.code_run(code: 'print("Hello World")')puts response.resultmain.go
// Import the Daytona SDKpackage main
import ( "context" "log"
"github.com/daytonaio/daytona/libs/sdk-go/pkg/daytona" "github.com/daytonaio/daytona/libs/sdk-go/pkg/types")
func main() { // Define the configuration config := &types.DaytonaConfig{ APIKey: "YOUR_API_KEY", // Replace with your API key }
// Initialize the Daytona client client, err := daytona.NewClientWithConfig(config) if err != nil { log.Fatal(err) }
ctx := context.Background()
// Create the Sandbox instance params := types.SnapshotParams{ SandboxBaseParams: types.SandboxBaseParams{ Language: types.CodeLanguagePython, }, } sandbox, err := client.Create(ctx, params) if err != nil { log.Fatal(err) }
// Run the code securely inside the Sandbox result, err := sandbox.Process.ExecuteCommand(ctx, `echo "Hello World"`)
// Check the response if err != nil { log.Fatalf("Error: %v", err) } if result.ExitCode != 0 { log.Printf("Error: %d %s", result.ExitCode, result.Result) } else { log.Println(result.Result) }
// Clean up sandbox.Delete(ctx)}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:
- Learn more about Daytona with the Getting Started guide
- Get started with Python, TypeScript, Ruby or Go SDKs
- Install the CLI to manage sandboxes from the command line
- Use the API to manage sandboxes programmatically
- View examples for common sandbox operations and best practices
- Explore guides to connect Daytona with Claude, OpenCode, Codex, LangChain and more