Sign Up

Daytona

Main class for interacting with the Daytona API. Provides methods for creating, managing, and interacting with Daytona Sandboxes. Can be initialized either with explicit configuration or using environment variables.

Properties:

  • secret SecretService - Service for managing Daytona Secrets
  • snapshot SnapshotService - Service for managing Daytona Snapshots
  • volume VolumeService - Service for managing Daytona Volumes
  • warmPool WarmPoolService - Service for managing Daytona Warm Pools

Examples:

// Using environment variables
// Uses DAYTONA_API_KEY, DAYTONA_API_URL, DAYTONA_TARGET
const daytona = new Daytona();
const sandbox = await daytona.create();
// Using explicit configuration
const config: DaytonaConfig = {
    apiKey: "your-api-key",
    apiUrl: "https://your-api.com",
    target: "us"
};
const daytona = new Daytona(config);
// Disposes daytona and flushes traces when done
await using daytona = new Daytona({
  otelEnabled: true,
});
@class

Implements

  • AsyncDisposable

Constructors

Constructor

new Daytona(config?: DaytonaConfig): Daytona;

Creates a new Daytona client instance.

Parameters:

  • config? DaytonaConfig - Configuration options

Returns:

  • Daytona

Throws:

When no credentials are provided (neither API key nor JWT token)

When JWT token is provided without an organization ID

Methods

_experimental_fork()

_experimental_fork(
   sandbox: Sandbox, 
   params?: ForkSandboxParams, 
timeout?: number): Promise<Sandbox>;

Parameters:

  • sandbox Sandbox
  • params? ForkSandboxParams
  • timeout? number = 60

Returns:

  • Promise<Sandbox>
Deprecated

Use fork instead. This method will be removed in a future version.

See

Daytona.fork

[asyncDispose]()

asyncDispose: Promise<void>;

Returns:

  • Promise<void>
Implementation of
AsyncDisposable.[asyncDispose]

create()

Call Signature
create(params?: CreateSandboxFromSnapshotParams, options?: {
  timeout?: number;
}): Promise<Sandbox>;

Creates Sandboxes from specified or default snapshot. You can specify various parameters, including language, image, environment variables, and volumes.

Parameters:

  • params? CreateSandboxFromSnapshotParams - Parameters for Sandbox creation from snapshot
  • options? Options for the create operation
  • timeout? number - Timeout in seconds (0 means no timeout, default is 60)

Returns:

  • Promise<Sandbox> - The created Sandbox instance

Examples:

const sandbox = await daytona.create();
// Create a custom sandbox
const params: CreateSandboxFromSnapshotParams = {
    language: 'typescript',
    snapshot: 'my-snapshot-id',
    envVars: {
        NODE_ENV: 'development',
        DEBUG: 'true'
    },
    autoStopInterval: 60,
    autoArchiveInterval: 60,
    autoDeleteInterval: 120
};
const sandbox = await daytona.create(params, { timeout: 100 });
Call Signature
create(params?: CreateSandboxFromImageParams, options?: {
  onSnapshotCreateLogs?: (chunk: string) => void;
  timeout?: number;
}): Promise<Sandbox>;

Creates Sandboxes from specified image available on some registry or declarative Daytona Image. You can specify various parameters, including resources, language, image, environment variables, and volumes. Daytona creates snapshot from provided image and uses it to create Sandbox.

Parameters:

  • params? CreateSandboxFromImageParams - Parameters for Sandbox creation from image
  • options? Options for the create operation
  • onSnapshotCreateLogs? (chunk: string) => void - Callback function to handle snapshot creation logs.
  • timeout? number - Timeout in seconds (0 means no timeout, default is 60)

Returns:

  • Promise<Sandbox> - The created Sandbox instance

Examples:

const sandbox = await daytona.create({ image: 'debian:12.9' }, { timeout: 90, onSnapshotCreateLogs: console.log });
// Create a custom sandbox
const image = Image.base('alpine:3.18').pipInstall('numpy');
const params: CreateSandboxFromImageParams = {
    language: 'typescript',
    image,
    envVars: {
        NODE_ENV: 'development',
        DEBUG: 'true'
    },
    resources: {
        cpu: 2,
        memory: 4 // 4GB RAM
    },
    autoStopInterval: 60,
    autoArchiveInterval: 60,
    autoDeleteInterval: 120
};
const sandbox = await daytona.create(params, { timeout: 100, onSnapshotCreateLogs: console.log });

delete()

delete(
   sandbox: Sandbox, 
   timeout?: number, 
wait?: boolean): Promise<void>;

Deletes a Sandbox.

Parameters:

  • sandbox Sandbox - The Sandbox to delete
  • timeout? number = 60 - Timeout in seconds (0 means no timeout, default is 60)
  • wait? boolean = false - If true, wait until the Sandbox is destroyed (default is false)

Returns:

  • Promise<void>

Example:

const sandbox = await daytona.get('my-sandbox-id');
await daytona.delete(sandbox);

fork()

fork(
   sandbox: Sandbox, 
   params?: ForkSandboxParams, 
timeout?: number): Promise<Sandbox>;

Forks a Sandbox, creating a new Sandbox with an identical filesystem.

Parameters:

  • sandbox Sandbox - The Sandbox to fork
  • params? ForkSandboxParams - Fork parameters
  • timeout? number = 60 - Timeout in seconds (0 means no timeout, default is 60)

Returns:

  • Promise<Sandbox> - The forked Sandbox

Example:

const sandbox = await daytona.get('my-sandbox-id');
const forked = await daytona.fork(sandbox, { name: 'my-fork' });
console.log(`Forked sandbox: ${forked.id}`);

get()

get(sandboxIdOrName: string): Promise<Sandbox>;

Gets a Sandbox by its ID or name.

Parameters:

  • sandboxIdOrName string - The ID or name of the Sandbox to retrieve

Returns:

  • Promise<Sandbox> - The Sandbox

Example:

const sandbox = await daytona.get('my-sandbox-id-or-name');
console.log(`Sandbox state: ${sandbox.state}`);

list()

list(query?: ListSandboxesQuery): AsyncIterableIterator<Sandbox>;

Iterates over Sandboxes matching the given query.

Parameters:

  • query? ListSandboxesQuery - Optional filters, sorting, and per-page size.
Returns

AsyncIterableIterator<Sandbox>

Example:

for await (const sandbox of daytona.list({ labels: { env: 'dev' } })) {
  console.log(sandbox.id)
}

start()

start(sandbox: Sandbox, timeout?: number): Promise<void>;

Starts a Sandbox and waits for it to be ready.

Parameters:

  • sandbox Sandbox - The Sandbox to start
  • timeout? number - Optional timeout in seconds (0 means no timeout)

Returns:

  • Promise<void>

Example:

const sandbox = await daytona.get('my-sandbox-id');
// Wait up to 60 seconds for the sandbox to start
await daytona.start(sandbox, 60);

stop()

stop(sandbox: Sandbox): Promise<void>;

Stops a Sandbox.

Parameters:

  • sandbox Sandbox - The Sandbox to stop

Returns:

  • Promise<void>

Example:

const sandbox = await daytona.get('my-sandbox-id');
await daytona.stop(sandbox);

CodeLanguage

Supported programming languages for code execution

Python is used as the default sandbox language when no language is explicitly specified.

Enum Members:

  • JAVASCRIPT ("javascript")
  • PYTHON ("python")
  • TYPESCRIPT ("typescript")

CreateSandboxBaseParams

Base parameters for creating a new Sandbox.

Properties:

  • autoArchiveInterval? number - Auto-archive interval in minutes (0 means the maximum interval will be used). Default is 7 days.
  • autoDeleteInterval? number - Auto-delete interval in minutes (negative value means disabled, 0 means delete immediately upon stopping). By default, auto-delete is disabled.
  • autoPauseInterval? number - Auto-pause interval in minutes (0 means disabled). Only supported for sandbox classes that support pausing. Not allowed for ephemeral sandboxes. At most one of autoStopInterval and autoPauseInterval may be non-zero. For non-ephemeral sandbox classes that support pausing, defaults to 60 minutes (with auto-stop disabled) when neither interval is provided.
  • autoStopInterval? number - Auto-stop interval in minutes (0 means disabled). Default is 15 minutes (for sandbox classes that support pausing, auto-pause defaults to 60 minutes instead and auto-stop is disabled).
  • domainAllowList? string - Comma-separated list of allowed domains for the Sandbox
  • envVars? Record<string, string> - Optional environment variables to set in the Sandbox
  • ephemeral? boolean - Whether the Sandbox should be ephemeral. If true, autoDeleteInterval will be set to 0.
  • labels? Record<string, string> - Sandbox labels
  • language? string - Programming language for direct code execution. Defaults to "python" if not specified.
  • linkedSandbox? string - ID or name of an existing sandbox to link the new sandbox to. The new sandbox will be scheduled on the same runner as the linked sandbox so a local network can be established between them. Linked sandboxes must be ephemeral (autoDeleteInterval=0) and cannot themselves be linked to another sandbox.
  • name? string
  • networkAllowList? string - Comma-separated list of allowed CIDR network addresses for the Sandbox
  • networkBlockAll? boolean - Whether to block all network access for the Sandbox
  • otelEndpointOverride? string - OTel collector endpoint override for the Sandbox. When set, sandbox OTel data is sent to this endpoint instead of the default collector and will not be available in the Daytona analytics API or dashboard.
  • outboundProxyUrl? string - Outbound proxy URL to route the Sandbox HTTP(S) traffic through. Applied via the HTTP(S)_PROXY environment variables (convenience routing, not a security boundary on its own); combine with domainAllowList for unbypassable network-layer enforcement.
  • public? boolean - Is the Sandbox port preview public
  • secrets? Record<string, string> - Optional map of environment variable name to the name of an existing organization Secret to mount into the Sandbox. The env var is set to the Secret's opaque placeholder; the real value is substituted transparently on outbound requests to the Secret's allowed hosts. Every referenced Secret name must already exist in the organization.
  • spot? boolean - GPU-only. When true, the Sandbox may be instantly terminated without notice to free GPU capacity for an on-demand (non-spot) GPU Sandbox. Rejected when the Sandbox requests no GPUs.
  • ttlMinutes? number - Maximum time to live in minutes, counted as wall-clock time since creation regardless of sandbox state (0 means disabled). When it elapses the Sandbox is destroyed, even if it is stopped, paused, or archived.
  • user? string - Optional os user to use for the Sandbox
  • volumes? VolumeMount[] - Optional array of volumes to mount to the Sandbox

CreateSandboxFromImageParams

Parameters for creating a new Sandbox.

Properties:

  • autoArchiveInterval? number
  • autoDeleteInterval? number
  • autoPauseInterval? number
  • autoStopInterval? number
  • domainAllowList? string
  • envVars? Record<string, string>
  • ephemeral? boolean
  • image string | Image - Custom Docker image to use for the Sandbox. If an Image object is provided, the image will be dynamically built.
  • labels? Record<string, string>
  • language? string
  • linkedSandbox? string
  • name? string
  • networkAllowList? string
  • networkBlockAll? boolean
  • otelEndpointOverride? string
  • outboundProxyUrl? string
  • public? boolean
  • resources? Resources - Resource allocation for the Sandbox. If not provided, sandbox will have default resources.
  • secrets? Record<string, string>
  • spot? boolean
  • ttlMinutes? number
  • user? string
  • volumes? VolumeMount[]

CreateSandboxFromSnapshotParams

Parameters for creating a new Sandbox from a snapshot.

Properties:

  • autoArchiveInterval? number
  • autoDeleteInterval? number
  • autoPauseInterval? number
  • autoStopInterval? number
  • domainAllowList? string
  • envVars? Record<string, string>
  • ephemeral? boolean
  • labels? Record<string, string>
  • language? string
  • linkedSandbox? string
  • name? string
  • networkAllowList? string
  • networkBlockAll? boolean
  • otelEndpointOverride? string
  • outboundProxyUrl? string
  • public? boolean
  • secrets? Record<string, string>
  • snapshot? string - Name of the snapshot to use for the Sandbox.
  • spot? boolean
  • ttlMinutes? number
  • user? string
  • volumes? VolumeMount[]

DaytonaConfig

Configuration options for initializing the Daytona client.

Properties:

  • \_experimental? Record<string, any> - Configuration for experimental features

  • apiKey? string - API key for authentication with the Daytona API

  • apiUrl? string - URL of the Daytona API. Defaults to 'https://app.daytona.io/api' if not set here and not set in environment variable DAYTONA_API_URL.

  • jwtToken? string - JWT token for authentication with the Daytona API. If not set, it must be provided via the environment variable DAYTONA_JWT_TOKEN, or an API key must be provided instead.

  • organizationId? string - Organization ID used for JWT-based authentication. Required if a JWT token is provided, and must be set either here or in the environment variable DAYTONA_ORGANIZATION_ID.

  • otelEnabled? boolean - OpenTelemetry tracing enabled. If set, all SDK operations will be traced.

  • requestTimeoutMs? number - Maximum time in milliseconds the SDK waits for a single HTTP response before failing the request. Applies to the Daytona API client and to the toolbox clients of every Sandbox obtained from this Daytona instance. Defaults to 24 hours; 0 disables the deadline.

    This is a client-side deadline only — it does not cancel the operation on the server. Calls that carry their own operation or execution timeout (e.g. create, start, stop, fork, process.executeCommand, process.codeRun) are not capped by this value; their HTTP wait is bounded by that per-call timeout instead.

  • serverUrl? string - Deprecated - Use apiUrl instead. This property will be removed in future versions.

  • target? string - Target location for Sandboxes

  • useDeprecatedPolling? boolean - Observe sandbox state by legacy polling instead of WebSocket event streaming. Defaults to false, where state changes are streamed over WebSocket. Can also be enabled via the DAYTONA_USE_DEPRECATED_POLLING environment variable.

    streaming is the default and falls back to polling automatically when WebSockets are unavailable.

    • Deprecated - Polling-only mode will be removed in a future release. Event

Example:

const config: DaytonaConfig = {
    apiKey: "your-api-key",
    apiUrl: "https://your-api.com",
    target: "us"
};
const daytona = new Daytona(config);

Resources

Resource allocation for a Sandbox.

Properties:

  • cpu? number - CPU allocation for the Sandbox in cores
  • disk? number - Disk space allocation for the Sandbox in GiB
  • gpu? number - GPU allocation for the Sandbox in units
  • gpuType? GpuType | GpuType[] - Preferred GPU type for the Sandbox
  • memory? number - Memory allocation for the Sandbox in GiB

Example:

const resources: SandboxResources = {
    cpu: 2,
    memory: 4,  // 4GiB RAM
    disk: 20    // 20GiB disk
};

VolumeMount

Represents a volume mount for a Sandbox.

Properties:

  • mountPath string - Path on the Sandbox to mount the Volume

  • subpath? string - Optional subpath within the volume to mount. When specified, only this S3 prefix will be accessible. When omitted, the entire volume is mounted.

    • Inherited from: SandboxVolume.subpath
  • volumeId string - ID or name of the Volume to mount

Extends:

  • SandboxVolume

ForkSandboxParams

type ForkSandboxParams = {
  name?: string;
};

Properties:

  • name? string - Optional name for the forked Sandbox. If not provided, a unique name will be generated.

Parameters for forking a Sandbox.

CODE_TOOLBOX_LANGUAGE_LABEL

const CODE_TOOLBOX_LANGUAGE_LABEL: "code-toolbox-language" = 'code-toolbox-language';