Getting Started
The Daytona SDK provides official Python and TypeScript interfaces for interacting with Daytona, enabling you to programmatically manage development environments and execute code.
View the Daytona SDK repository on GitHub.
Follow the step by step guide to create and run your first Daytona Sandbox for an AI Agent.
Install Daytona
Install Daytona by following the installation instructions. If you have Beta access to the Daytona platform, create an account and log in.
Set Up Your Environment Variables
To authenticate with Daytona, you need an API key. You can obtain an API key from the Daytona platform or generate one using the Daytona CLI.
- Navigate to the Daytona platform.
- Go to API Keys.
- Click the
Create Key
button. - Paste the API key in your
.env
file.
- Type the following command:
daytona api-key generate
- Paste the API key in your
.env
file.
Install the Daytona SDK
Daytona provides official Python and TypeScript SDKs for interacting with the Daytona platform. Install the SDK using your preferred method.
pip install daytona-sdk
# Using npmnpm install @daytonaio/sdk
# Using yarn
yarn add @daytonaio/sdk
# Using pnpm
pnpm add @daytonaio/sdk
Write Code to Create a Sandbox
Create and run your code within Daytona Sandboxes using the SDK. Daytona provides a simple and intuitive interface for interacting with Daytona.
Use the Daytona SDK Python examples or TypeScript/JavaScript examples to create a Sandbox and run your code.
Execute Commands
Run the following code to create a Daytona Sandbox and execute commands:
from daytona_sdk import Daytona, CreateWorkspaceParams
# Initialize the Daytona clientdaytona = Daytona()
# Create the Sandbox instanceparams = CreateWorkspaceParams(language="python")workspace = daytona.create(params)
# Run the code securely inside the Sandboxresponse = workspace.process.code_run('print("Sum of 3 and 4 is " + str(3 + 4))')if response.exit_code != 0: print(f"Error running code: {response.exit_code} {response.result}")else: print(response.result)
# Clean up the Sandboxdaytona.remove(workspace)
import { Daytona } from '@daytonaio/sdk'
async function main() { // Initialize the Daytona client const daytona = new Daytona()
try { // Create the workspace instance const workspace = await daytona.create({ language: 'python', }) // Run the code securely inside the workspace const response = await workspace.process.codeRun( 'print("Sum of 3 and 4 is " + str(3 + 4))', ) if (response.exitCode !== 0) { console.error('Error running code:', response.exitCode, response.result) } else { console.log(response.result) } } catch (error) { console.error('Workspace flow error:', error) } finally { // Clean up the workspace await daytona.remove(workspace) }}
main()
Start your Sandbox
Daytona provides two methods for starting your Sandbox:
- Using Python
- Using TypeScript/JavaScript
Choose the appropriate method based on your preferred language.
python main.py
npx tsx ./index.ts