Daytona

Full-featured Daytona sandboxes through the stable v0 surface of @daytona/sdk. Streaming exec, PTY, code interpreter with stateful Python kernels, pause/stop, snapshots, fork, SSH, egress allow lists, vault secrets, volumes, metrics, browser-safe signed previews, and Dockerfile template builds.

Installation

@daytona/sdk (≥ 2.0) is an optional peer dependency of sbox-sdk, loaded lazily on first use.

pnpm add sbox-sdk @daytona/sdk

Moved from @daytonaio/sdk

@daytonaio/sdk is deprecated; Daytona now publishes @daytona/sdk. 2.x ships a stable v0 API and an alpha v2 API. The adapter uses v0 (reached through the root client's daytona.v0). Uninstall @daytonaio/sdk when you upgrade.

Authentication

A single API key (plus an optional region).

Authentication variables for the daytona adapter.
OptionEnv varRequiredDescription
apiKeyDAYTONA_API_KEYrequiredYour Daytona API key.
apiUrlDAYTONA_API_URLoptionalOverride the Daytona API URL (self-hosted).
targetDAYTONA_TARGEToptionalTarget region, e.g. "us" or "eu".

Pass apiKey (or jwtToken + organizationId). SDK 2.x ignores DAYTONA_API_URL. For a self-hosted or dev API, pass apiUrl, and the adapter builds the v0 client against it directly.

Quickstart

import { createSandboxClient } from "sbox-sdk";
import { daytona } from "sbox-sdk/daytona";

const client = createSandboxClient({
  provider: daytona({ apiKey: process.env.DAYTONA_API_KEY!, target: "us" }),
});

const sandbox = await client.create({
  template: "debian:12", // image ref → built on the fly; a bare name → Daytona snapshot
  metadata: { job: "demo" },
  lifecycle: {
    idleTimeoutMs: 15 * 60_000,
    onIdle: "pause",
    maxAgeMs: 4 * 3_600_000,
  },
});

for await (const ev of sandbox.commands.run("echo out; echo err >&2")) {
  console.log(ev);
}

const ctx = await sandbox.code.createContext(); // stateful Python kernel
await sandbox.code.runCode("x = 41", { context: ctx });
console.log(
  (await sandbox.code.runCode("print(x + 1)", { context: ctx })).logs.stdout
);

await sandbox.pause(); // memory kept
await sandbox.resume();
await sandbox.destroy();

template is a Daytona snapshot name, or a container image when it contains / or :. fromSnapshot takes a snapshot name, for example one from sandbox.snapshots.create().

Options

Prop

Type

Templates (Dockerfile builds)

client.templates.build() builds a Daytona snapshot in your organization. A Dockerfile goes through Image.fromDockerfile(), and an image source goes through Image.base(). The result is passed to daytona.snapshot.create({ name, image, resources }, { onLogs }), and build logs stream through onEvent.

const tpl = await client.templates.build(
  {
    name: "borat-desktop",
    source: {
      dockerfile: await readFile("desktop/Dockerfile", "utf8"),
      context: "./desktop",
    },
    env: { DISPLAY: ":1" },
    workdir: "/app",
    resources: { vcpus: 2, memoryMB: 4096, diskMB: 10_240 },
    startCmd: "/usr/local/bin/start-vnc.sh",
  },
  { onEvent: (e) => e.type === "log" && console.log(e.line) }
);
const desktop = await client.create({ template: tpl });
  • The snapshot is named <name>-<first 16 hex of the cache key> (just sbox-<key> when you don't set a name), so lookup(cacheKey) and later builds find it again.
  • The context is written to a temp directory next to the Dockerfile, so COPY/ADD work. This needs Node.
  • startCmd becomes the snapshot entrypoint (sh -c …). readyCmd isn't supported and is ignored with a log line. user adds a USER instruction.
  • resources apply to the snapshot (cpu, memory/disk in GiB, gpu). Snapshot sources aren't accepted. registryAuth isn't either: configure private registries in the Daytona dashboard.

Previews and browser auth

  • ports.expose(port) returns Daytona's standard preview link (https://<port>-<id>.<proxy>). For a private sandbox it carries auth: { type: "header", headers: { "X-Daytona-Preview-Token": … } }. That token works for every port and can't be revoked, so treat it as a secret.
  • ports.expose(port, { visibility: "private" }) returns a signed preview URL (https://<port>-<token>.<proxy>) with auth: { type: "signed-url" }. The token is in the hostname, so it works from a browser, an iframe, or a WebSocket (flags.previewBrowserAuth: true). It's scoped to one port and expires after previewTtlSeconds (default 3600, max 86 400). Daytona's proxy closes WebSockets opened with it about a minute after expiry.

Lifecycle

SandboxSpecDaytona
lifecycle.idleTimeoutMsautoStopInterval (minutes), or autoPauseInterval when onIdle: "pause"
onIdle: "destroy"autoDeleteInterval: 0 (deleted as soon as it stops, including stop())
lifecycle.maxAgeMsttlMinutes: wall-clock limit since creation, destroys even if stopped
setTimeout(ms)setTtl(): re-anchors the wall-clock TTL from now (not the idle timer)
autoArchiveInterval optautoArchiveInterval (minutes a stopped sandbox waits before archiving)

Daytona counts idle time from SDK activity, not preview traffic. getInfo() refreshes from the API and maps every Daytona state (started, pausing, archived, build_failed, …) to SandboxState. stop() keeps the disk, and pause() keeps memory.

Network, secrets and volumes

  • Egress: block-all → networkBlockAll, allow-list → networkAllowList (CIDRs) and domainAllowList, both at create and at runtime (updateNetworkSettings). Deny rules and inject aren't supported.
  • Secrets: a SecretRef without a value mounts an existing Daytona vault Secret (secrets: { [envVar]: name }). The env var holds a placeholder, and the real value is substituted on egress to the Secret's allowed hosts. An inline value becomes a plain env var.
  • Volumes: client.volumes wraps daytona.volume (no size or region). spec.volumes mounts by id or name. Read-only mounts aren't supported.
  • Idempotency: each create gets a deterministic name from the idempotency key, so a retried create that hits 409 returns the existing sandbox. getOrCreate is native (daytona.get(name), resuming it if stopped).

Capabilities

CapabilityLevelNotes
list / stop / pause / setTimeoutnativelist filters by labels and state on the server
streaming / background / killProcessnativeone Daytona session per command; kill deletes the session
stdinnativesendSessionCommandInput
ptynativecreatePty / connectPty, resize
filesUploadnativestreaming upload; filesWatch unsupported
codeInterpreter / statefulKernelnativecontexts = codeInterpreter.createContext (Python only)
exposePort / privatePreviewnativesigned URLs, previewBrowserAuth: true
egressControl / secretsVaultnativeallow lists only
snapshot / forknativefilesystem snapshots (includesMemory: false); fork = CoW clone
sshnativetoken auth: ssh <token>@ssh.app.daytona.io; privateKey is empty
metrics / volumes / templateBuildnativesources: dockerfile, image
gpu / regionnativeresources.gpu → gpuType; region → target
proxiedFetch / filesWatchunsupported

Flags: preservesMemoryOnPause: true, preservesDiskOnStop: true, perCommandEnvCwd: false (the core prefixes cd/export), exitCodeNative: true, previewBrowserAuth: true, previewModel: "subdomain".

Known limitations

  • resources only apply to image-based creates (template: "debian:12"). On snapshot-based creates they throw Validation, so set them on the template instead.
  • Commands run in Daytona sessions, so output arrives through the log stream rather than a raw pipe. Exit codes come from getSessionCommand.
  • snapshots.create({ mode: "memory" }) throws (Daytona snapshots are filesystem-only). Restoring always boots a new sandbox, so use client.create({ fromSnapshot }).
  • Daytona timeouts are in seconds or minutes. The adapter rounds milliseconds up.

On this page