--- title: Configuration --- import { Tabs, TabItem } from '@astrojs/starlight/components'; The Daytona SDK provides flexible configuration options to customize its behavior and connection settings. ## Configuration Options Daytona SDK provides an option to configure settings using the `DaytonaConfig` class in Python and TypeScript. The `DaytonaConfig` class accepts the following parameters: - `api_key`: Your Daytona API key - `server_url`: URL of your Daytona server - `target`: Daytona Target to create the Sandboxes on. ```python from daytona_sdk import DaytonaConfig config = DaytonaConfig( api_key="your-api-key", server_url="your-server-url", target="us" ) ``` ```typescript import { DaytonaConfig } from '@daytonaio/sdk'; const config: DaytonaConfig = { apiKey: "your-api-key", serverUrl: "your-server-url", target: "us" }; ``` ## Environment Variables Daytona SDK supports environment variables for configuration. The SDK automatically looks for these environment variables: | Variable | Description | Default | |----------|-------------|---------| | **`DAYTONA_API_KEY`** | Your Daytona API key. | None | | **`DAYTONA_SERVER_URL`** | URL of your Daytona server. | None | | **`DAYTONA_TARGET`** | Daytona Target to create the Sandboxes on. | "us" | ### Setting Environment Variables Daytona SDK can read configuration from environment variables. You can set these environment variables using the following methods: - [Using a **`.env`** file](#using-a-env-file) - [Using Shell Environment](#using-shell-environment) #### Using a **`.env`** File Create a `.env` file in your project root directory: ```bash DAYTONA_API_KEY=your-api-key DAYTONA_SERVER_URL=https://your-server-url DAYTONA_TARGET=us ``` - `DAYTONA_API_KEY`: Your Daytona API key. - `DAYTONA_SERVER_URL`: URL of your Daytona server. - `DAYTONA_TARGET`: Daytona Target to create the Sandboxes on. #### Using Shell Environment Set environment variables in your shell: ```bash export DAYTONA_API_KEY=your-api-key export DAYTONA_SERVER_URL=https://your-server-url ``` ```bash $env:DAYTONA_API_KEY="your-api-key" $env:DAYTONA_SERVER_URL="https://your-server-url" ``` ## Configuration Precedence The SDK uses the following precedence order for configuration (highest to lowest): 1. Explicitly passed configuration in code. 2. Environment variables. 3. Configuration file. 4. Default values. --- title: Getting Started --- import { Tabs, TabItem } from '@astrojs/starlight/components'; 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](https://github.com/daytonaio/sdk). Follow the step by step guide to create and run your first Daytona Sandbox for an AI Agent. ## Set Up Your Environment Variables To authenticate with Daytona, you need an API key. You can obtain an API key from the Daytona platform. 1. Navigate to the Daytona platform. 2. Go to API Keys. 3. Click the **`Create Key`** button. 4. Add your API key to your **`.env`** file by setting the **`DAYTONA_API_KEY`** environment variable. 5. Define the Daytona server URL in your **`.env`** file by setting the **`DAYTONA_SERVER_URL`** environment variable. ## Install the Daytona SDK Daytona provides official Python and TypeScript SDKs for interacting with the Daytona platform. Install the SDK using your preferred method. ```bash pip install daytona-sdk ``` ```bash # Using npm npm 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](https://github.com/daytonaio/sdk/tree/main/examples/python) or [TypeScript/JavaScript examples](https://github.com/daytonaio/sdk/tree/main/examples/typescript) to create a Sandbox and run your code. ### Execute Commands Run the following code to create a Daytona Sandbox and execute commands: ```python 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) ``` ```typescript 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. ```bash python main.py ``` ```bash npx tsx ./index.ts ``` --- title: Daytona Documentation description: Start managing your Sandboxes with Daytona. template: doc head: - tag: title content: Documentation · Daytona - tag: meta attrs: property: og:title content: Documentation · Daytona - tag: meta attrs: name: twitter:title content: Documentation · Daytona tableOfContents: false --- import { Tabs, TabItem } from '@astrojs/starlight/components'; The Daytona SDK provides official Python and TypeScript interfaces for interacting with Daytona, enabling you to programmatically manage development environments and execute code. ### Quick Start ```bash pip install daytona_sdk ``` ```python from daytona_sdk import Daytona, DaytonaConfig # Define the configuration config = DaytonaConfig( api_key="your-api-key", server_url="your-server-url", target="us" ) # Initialize the Daytona client daytona = Daytona(config) # Create the Sandbox instance workspace = daytona.create() # Run the code securely inside the Sandbox response = workspace.process.code_run('print("Hello World from code!")') if response.exit_code != 0: print(f"Error: {response.exit_code} {response.result}") else: print(response.result) daytona.remove(workspace) ``` ```bash npm install @daytonaio/sdk ``` ```typescript import { Daytona } from '@daytonaio/sdk'; // Initialize the Daytona client const daytona = new Daytona({ apiKey: 'your-api-key', serverUrl: 'your-server-url', target: 'us' }); // Create the Sandbox instance const workspace = await daytona.create({ language: 'typescript', }); // Run the code securely inside the Sandbox const response = await workspace.process.codeRun('console.log("Hello World from code!")') console.log(response.result); ``` --- title: Sandbox Persistence --- Daytona keeps the filesystem in its entirety during the sandbox lifecycle. The persistence functionality is built into the system, and nothing needs to be explicitly done from the user side. ## Understanding Sandbox States It is important to understand the sandbox states to maintain cost-effectiveness. A sandbox can have three states during its lifecycle: ### Running Running sandboxes utilize CPU, memory, and disk storage. Every resource is charged per second of usage. When sandboxes are not actively used, it is recommended that they be stopped. This can be done: - Manually using the stop command - Automatically by setting the autoStop interval ### Stopped Stopped sandboxes only utilize disk storage. They can be instantly started when needed. The stopped state should be used when the sandbox is expected to be started again soon. Otherwise, it is recommended to archive the sandbox to eliminate disk usage costs. ### Archived When sandboxes are archived, the entire filesystem state is moved to very cost-effective object storage, making it possible to keep sandboxes available for an extended period. ## Performance Considerations The tradeoff between archived and stopped states is that starting an archived sandbox takes more time, depending on its size.