Skip to content

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.

  1. Navigate to the Daytona platform.
  2. Go to API Keys.
  3. Click the Create Key button.
  4. 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.

Terminal window
pip install daytona-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 client
daytona = Daytona()
# Create the Sandbox instance
params = CreateWorkspaceParams(language="python")
workspace = daytona.create(params)
# Run the code securely inside the Sandbox
response = 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 Sandbox
daytona.remove(workspace)

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.

Terminal window
python main.py