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/sdkMoved 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).
| Option | Env var | Required | Description |
|---|---|---|---|
apiKey | DAYTONA_API_KEY | required | Your Daytona API key. |
apiUrl | DAYTONA_API_URL | optional | Override the Daytona API URL (self-hosted). |
target | DAYTONA_TARGET | optional | Target 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>(justsbox-<key>when you don't set a name), solookup(cacheKey)and later builds find it again. - The context is written to a temp directory next to the Dockerfile, so
COPY/ADDwork. This needs Node. startCmdbecomes the snapshotentrypoint(sh -c …).readyCmdisn't supported and is ignored with a log line.useradds aUSERinstruction.resourcesapply to the snapshot (cpu,memory/diskin GiB,gpu). Snapshot sources aren't accepted.registryAuthisn'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 carriesauth: { 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>) withauth: { 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 afterpreviewTtlSeconds(default 3600, max 86 400). Daytona's proxy closes WebSockets opened with it about a minute after expiry.
Lifecycle
SandboxSpec | Daytona |
|---|---|
lifecycle.idleTimeoutMs | autoStopInterval (minutes), or autoPauseInterval when onIdle: "pause" |
onIdle: "destroy" | autoDeleteInterval: 0 (deleted as soon as it stops, including stop()) |
lifecycle.maxAgeMs | ttlMinutes: 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 opt | autoArchiveInterval (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) anddomainAllowList, both at create and at runtime (updateNetworkSettings). Deny rules andinjectaren't supported. - Secrets: a
SecretRefwithout avaluemounts 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 inlinevaluebecomes a plain env var. - Volumes:
client.volumeswrapsdaytona.volume(no size or region).spec.volumesmounts by id or name. Read-only mounts aren't supported. - Idempotency: each create gets a deterministic
namefrom the idempotency key, so a retried create that hits 409 returns the existing sandbox.getOrCreateis native (daytona.get(name), resuming it if stopped).
Capabilities
| Capability | Level | Notes |
|---|---|---|
list / stop / pause / setTimeout | native | list filters by labels and state on the server |
streaming / background / killProcess | native | one Daytona session per command; kill deletes the session |
stdin | native | sendSessionCommandInput |
pty | native | createPty / connectPty, resize |
filesUpload | native | streaming upload; filesWatch unsupported |
codeInterpreter / statefulKernel | native | contexts = codeInterpreter.createContext (Python only) |
exposePort / privatePreview | native | signed URLs, previewBrowserAuth: true |
egressControl / secretsVault | native | allow lists only |
snapshot / fork | native | filesystem snapshots (includesMemory: false); fork = CoW clone |
ssh | native | token auth: ssh <token>@ssh.app.daytona.io; privateKey is empty |
metrics / volumes / templateBuild | native | sources: dockerfile, image |
gpu / region | native | resources.gpu → gpuType; region → target |
proxiedFetch / filesWatch | unsupported |
Flags: preservesMemoryOnPause: true, preservesDiskOnStop: true, perCommandEnvCwd: false (the core prefixes cd/export), exitCodeNative: true, previewBrowserAuth: true, previewModel: "subdomain".
Known limitations
resourcesonly apply to image-based creates (template: "debian:12"). On snapshot-based creates they throwValidation, 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 useclient.create({ fromSnapshot }).- Daytona timeouts are in seconds or minutes. The adapter rounds milliseconds up.
E2B
The reference cloud adapter. Code interpreter, memory pause/resume, memory or filesystem snapshots, fork, PTY, egress rules with secret injection, volumes, and Dockerfile template builds. Backed by @e2b/code-interpreter.
Vercel Sandbox
Named, persistent Firecracker microVMs on Vercel. Streaming exec with real kill, a PTY, snapshots and forks, Drives, egress policy with credential injection, and public port URLs.