Daytona

repository·main·Indexed 13 days ago

https://github.com/daytonaio/daytona

A secure and elastic infrastructure runtime for executing AI-generated code and managing agent workflows. Daytona provides isolated, high-performance sandboxes that act as full composable computers with dedicated kernels, filesystems, and network stacks. It features SDKs for Python, TypeScript, Ruby, Go, and Java, as well as a CLI and REST API for sandbox management.

Tokens
1.6K
Snippets
4
Records
6
Agent score
50%

What's inside Daytona

  1. How Daytona sandboxes work

    main

    Daytona sandboxes are isolated, full composable computers designed for secure and elastic execution of AI-generated code and agent workflows.

    Key Characteristics:

    • Isolation: Each sandbox provides a dedicated kernel, filesystem, network stack, and allocated vCPU, RAM, and disk.
    • Speed: Sandboxes can spin up in under 90ms.
    • Compatibility: Built on OCI/Docker compatibility.
    • Persistence: Supports unlimited persistence and stateful environment snapshots to enable persistent agent operations across sessions.
    • Runtimes: Supports Python, TypeScript, and JavaScript.
  2. Daytona Platform Architecture

    main

    The Daytona platform is organized into three distinct planes:

    1. Interface plane: Provides the client interfaces (SDKs, CLI, API) used to interact with Daytona.
    2. Control plane: Orchestrates all sandbox operations and lifecycle management.
    3. Compute plane: The layer that actually runs and manages the sandbox instances.
  3. Install the Daytona SDKs

    main

    Daytona provides official SDKs for several programming languages to interact with sandboxes programmatically. Choose the installation command corresponding to your preferred runtime:

    • Python: pip install daytona
    • TypeScript: npm install @daytona/sdk
    • Ruby: gem install daytona
    • Go: go get github.com/daytonaio/daytona/libs/sdk-go
    • Java (Gradle): Add implementation("io.daytona:sdk:x.y.z") to your dependencies.
    • Java (Maven): Add the io.daytona:sdk dependency to your pom.xml.
    # Python
    pip install daytona
    
    # TypeScript
    npm install @daytona/sdk
    
    # Ruby
    gem install daytona
    
    # Go
    go get github.com/daytonaio/daytona/libs/sdk-go
  4. Quick Start: Create and execute code in a sandbox

    main

    To use Daytona, first create an account at app.daytona.io and generate an API key. You can then use the following patterns to spin up a sandbox and execute code.

    ### Python SDK
    ```py
    from daytona import Daytona, DaytonaConfig
    
    config = DaytonaConfig(api_key="YOUR_API_KEY")
    daytona = Daytona(config)
    sandbox = daytona.create()
    response = sandbox.process.code_run('print("Hello World!")')
    print(response.result)

    TypeScript SDK

    import { Daytona } from "@daytona/sdk";
    
    const daytona = new Daytona({ apiKey: "YOUR_API_KEY" });
    const sandbox = await daytona.create();
    const response = await sandbox.process.codeRun('print("Hello World!")');
    console.log(response.result);

    Ruby SDK

    require 'daytona'
    
    config = Daytona::Config.new(api_key: 'YOUR_API_KEY')
    daytona = Daytona::Daytona.new(config)
    sandbox = daytona.create
    response = sandbox.process.code_run(code: 'print("Hello World!")')
    puts response.result

    Go SDK

    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"}
      client, _ := daytona.NewClientWithConfig(config)
      ctx := context.Background()
      sandbox, _ := client.Create(ctx, nil)
      response, _ := sandbox.Process.ExecuteCommand(ctx, "echo 'Hello World!'")
      fmt.Println(response.Result)
    }

    Java SDK

    import io.daytona.sdk.Daytona;
    import io.daytona.sdk.DaytonaConfig;
    import io.daytona.sdk.Sandbox;
    import io.daytona.sdk.model.ExecuteResponse;
    
    public class Main {
      public static void main(String[] args) {
        DaytonaConfig config = new DaytonaConfig.Builder()
            .apiKey("YOUR_API_KEY")
            .build();
        try (Daytona daytona = new Daytona(config)) {
          Sandbox sandbox = daytona.create();
          ExecuteResponse response = sandbox.getProcess().executeCommand("echo 'Hello World!'");
          System.out.println(response.getResult());
        }
      }
    }
  5. Interact with Daytona via REST API

    main

    You can interact with the Daytona platform using standard REST calls. To create a sandbox, send a POST request to the sandbox endpoint with your API key in the Authorization header.

    curl 'https://app.daytona.io/api/sandbox' \
      --request POST \
      --header 'Authorization: Bearer <YOUR_API_KEY>' \
      --header 'Content-Type: application/json' \
      --data '{}'