Choose your preferred language and install the Daytona SDK:
pip install daytona
2
Set your API key
Set your API key as an environment variable:
export DAYTONA_API_KEY="your-api-key-here"
You can also pass the API key directly in your code. See the authentication guide for more options.
3
Create and run a sandbox
Create a simple program that creates a sandbox and runs code inside it:
Python
TypeScript
Go
Ruby
from daytona import Daytona# Initialize the Daytona clientdaytona = Daytona()# Create the sandboxsandbox = daytona.create()# Run code securely inside the sandboxresponse = sandbox.process.code_run('print("Sum of 3 and 4 is", 3 + 4)')print(response.result)# Clean updaytona.delete(sandbox)
import { Daytona } from '@daytonaio/sdk'async function main() { // Initialize the Daytona client const daytona = new Daytona() let sandbox try { // Create the sandbox sandbox = await daytona.create() // Run code securely inside the sandbox const response = await sandbox.process.codeRun( 'console.log("Sum of 3 and 4 is", 3 + 4)' ) console.log(response.result) } finally { if (sandbox) await daytona.delete(sandbox) }}main().catch(console.error)
package mainimport ( "context" "fmt" "log" "github.com/daytonaio/daytona/libs/sdk-go/pkg/daytona" "github.com/daytonaio/daytona/libs/sdk-go/pkg/types")func main() { // Initialize the Daytona client client, err := daytona.NewClient() if err != nil { log.Fatal(err) } ctx := context.Background() // Create the sandbox params := types.SnapshotParams{ SandboxBaseParams: types.SandboxBaseParams{ Language: types.CodeLanguagePython, }, } sandbox, _, err := client.Create(ctx, params) if err != nil { log.Fatal(err) } defer sandbox.Delete(ctx) // Run code securely inside the sandbox response, err := sandbox.Process.ExecuteCommand( ctx, `python3 -c "print('Sum of 3 and 4 is', 3 + 4)"`, ) if err != nil { log.Fatal(err) } fmt.Println(response.Result)}
require 'daytona'# Initialize the Daytona clientdaytona = Daytona::Client.newbegin # Create the sandbox sandbox = daytona.create # Run code securely inside the sandbox response = sandbox.process.code_run('puts "Sum of 3 and 4 is #{3 + 4}"') puts response.resultensure # Clean up daytona.delete(sandbox) if sandboxend
4
Run your program
Execute your program and you’ll see the output:
Sum of 3 and 4 is 7
Congratulations! You’ve successfully created your first Daytona sandbox and executed code inside it.