Threads AI

daytona

A Sandbox on Daytona.

Pass it as agent({sandbox: daytona()}). Each sandbox is private, starts with no environment and its network blocked, and stops, then is deleted, after autoStopMinutes idle as a backstop to the ledger's cleanup. The API key authenticates the host's requests only.

Import from @threads/daytona (TypeScript) or threads.daytona (Python).

function daytona(options?: {
  apiKey?: string | Secret;
  apiUrl?: string;
  snapshot?: string;
  target?: string;
  lifetimeMs?: number;
  allowInternet?: boolean;
  autoStopMinutes?: number;
  fetch?: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
  openSocket?: OpenSocket;
  pollMs?: number;
  waitMs?: number;
}): Sandbox

Parameters

apiKey / api_keystring | Secret

The Daytona API key: a secret() or a string. Omitted: secret("DAYTONA_API_KEY"). Resolved on the host at setup (check() or the first run); unset is missing_secret naming the option and the variable. It never enters a sandbox.

apiUrl / api_urlstringdefault https://app.daytona.io/api

The Daytona API URL.

snapshotstring

The Daytona snapshot a new sandbox starts from. Omitted: Daytona's default snapshot.

targetstring

The Daytona region (target) sandboxes are created in. Omitted: the organization's default.

lifetimeMs / lifetime_msnumberdefault 3600000

How long a sandbox lives, in milliseconds, before Daytona deletes it (the declared expiry). Daytona counts whole minutes, so it is rounded up to a whole minute. A positive integer; anything else is invalid_config.

allowInternet / allow_internetbooleandefault false

Lifts Daytona's network block. Egress is then unenforced, so the agent must also set egress: "unenforced".

autoStopMinutes / auto_stop_minutesnumberdefault 60

Idle minutes before Daytona stops a sandbox, and minutes after that before it deletes it: a backstop for a leak, never the normal cleanup. A positive integer; anything else is invalid_config.

fetch(input: string | URL | Request, init?: RequestInit) => Promise<Response>

TypeScript only. Seam: the fetch the API clients send through (a proxy, a test server); the run's fence wraps it either way. Omitted: the global fetch.

openSocketOpenSocket

TypeScript only. Seam: opens the exec log WebSocket (tests). Omitted: the runtime's WebSocket with headers; the fence checks each open either way.

pollMsnumberdefault 1000

TypeScript only. Seam: how often a wait for a sandbox state polls, in milliseconds.

waitMsnumberdefault 300000

TypeScript only. Seam: how long a wait for a sandbox state polls before it fails, in milliseconds.

namestrdefault daytona

Python only. The provider name in SandboxInfo and the sandbox ledger ([a-z][a-z0-9_]*, else invalid_config); rows under another name are never touched.

Returns

Sandbox

Throws ConfigError with one of these codes: invalid_config, missing_secret.

Edit on GitHub

On this page