---
title: Daytona
description: Run sandboxes on Daytona, or move E2B code to it by changing one line. Exact sizes, idle auto-stop, lifetimes, allow lists, snapshots, volumes, and previews.
---

`daytona()` runs each sandbox on [Daytona](https://daytona.io). It calls Daytona's HTTP API directly, so it needs no other package.

To switch from E2B to Daytona without rewriting your code, write it against `@opencoredev/sandbox-sdk` and change `createSandbox(e2b())` to `createSandbox(daytona())`. `box.run`, `box.files`, background processes and previews work the same. Daytona has no pause or resume, and its previews need a token header unless you set `daytona({ public: true })`, so check those against the [capability matrix](/docs/reference/capabilities) first. [E2B SDK and API in TypeScript](https://sandbox-sdk.app/blog/e2b-sdk-api-typescript) shows one task on both.

## Install

**npm**

```bash
npm install @opencoredev/sandbox-sdk
```

**pnpm**

```bash
pnpm add @opencoredev/sandbox-sdk
```

**yarn**

```bash
yarn add @opencoredev/sandbox-sdk
```

**bun**

```bash
bun add @opencoredev/sandbox-sdk
```

Set `DAYTONA_API_KEY` on your server, and keep it out of browser bundles. Your Daytona organization needs a default region, set in the Daytona Dashboard.

## Quickstart

```ts
import { createSandbox } from "@opencoredev/sandbox-sdk";
import { daytona } from "@opencoredev/sandbox-sdk/daytona";

await using box = await createSandbox(daytona());
const result = await box.run("uname -a");
console.log(result.stdout);
```

`await using` deletes the sandbox when the block ends.

## What it supports

| Feature                        | Support     | Notes                                                            |
| ------------------------------ | ----------- | ---------------------------------------------------------------- |
| Commands and streaming         | Yes         | Live output when you iterate                                     |
| Files                          | Yes         |                                                                  |
| Background processes           | Yes         |                                                                  |
| Preview URLs                   | Yes         | Send the `X-Daytona-Preview-Token` header, or set `public: true` |
| Pause and resume               | No          |                                                                  |
| Snapshots                      | Yes         | File system only. `expiresInMs` fails with `unsupported`         |
| Machine size                   | Yes         | Presets or exact CPU, memory, and disk                           |
| Network policy                 | Yes         | `"none"` or a host allow list                                    |
| Hard lifetime (`timeoutMs`)    | Yes         | Whole minutes, at least one                                      |
| Idle timeout (`idleTimeoutMs`) | Yes         | Whole minutes; the sandbox stops                                 |
| Keys                           | Best-effort | Found by label search                                            |
| Terminal                       | No          |                                                                  |

The [capability matrix](/docs/reference/capabilities) compares these with every other provider.

## Run commands

Await `box.run` for the result, or iterate it to stream output as it arrives.

```ts
import { createSandbox } from "@opencoredev/sandbox-sdk";
import { daytona } from "@opencoredev/sandbox-sdk/daytona";

await using box = await createSandbox(daytona());
const result = await box.run("ls -la", { cwd: "/workspace", timeoutMs: 30_000 });
console.log(result.exitCode, result.stdout);

for await (const chunk of box.run("for i in 1 2 3; do echo $i; sleep 1; done")) {
  process.stdout.write(chunk.text);
}
```

## Files

Relative paths resolve against `/workspace`.

```ts
import { createSandbox } from "@opencoredev/sandbox-sdk";
import { daytona } from "@opencoredev/sandbox-sdk/daytona";

await using box = await createSandbox(daytona());
await box.files.write("notes/todo.txt", "ship the docs\n");
console.log(await box.files.read("notes/todo.txt"));
console.log(await box.files.list("notes"));
await box.files.write("secrets/token", "abc123", { mode: 0o600 });
```

`{ mode }` sets the file's permissions through Daytona's file API right after the upload.

## Background processes and previews

No ports to declare. Sandboxes are private, so send `preview.headers` with every request.

```ts
import { createSandbox } from "@opencoredev/sandbox-sdk";
import { daytona } from "@opencoredev/sandbox-sdk/daytona";

await using box = await createSandbox(daytona());
await box.start("python3 -m http.server 3000", { name: "web", ready: { port: 3000 } });
const preview = await box.preview(3000, { waitMs: 10_000 });
const response = await fetch(preview.url, { headers: preview.headers });
console.log(response.status);
```

A browser can't add headers to an iframe or link. To show a preview to a user, proxy it through your server, or create the sandbox with `daytona({ public: true })`. Then anyone with the URL can open it, and `preview.headers` is undefined.

## Pause, resume, and snapshots

This adapter has no pause or resume, and the methods don't exist on its sandbox type. `snapshot()` captures the file system as a new Daytona snapshot and returns its name, which `from` accepts.

```ts
import { createSandbox, hasCapability } from "@opencoredev/sandbox-sdk";
import { daytona } from "@opencoredev/sandbox-sdk/daytona";

await using box = await createSandbox(daytona(), { key: "user:123" });
if (hasCapability(box, "pause")) await box.pause();

const { id } = await box.snapshot();
await using copy = await createSandbox(daytona(), { from: id });
```

The adapter waits up to ten minutes for a snapshot. If it times out, the error includes the snapshot name; the snapshot may still finish. Destroying a sandbox does not delete its snapshots. Daytona snapshots have no expiry, so `snapshot({ expiresInMs })` fails with `unsupported`. `expiresInMs: 0` is accepted.

## Size, network, and lifetime

| Preset   | CPUs | Memory   | Disk   |
| -------- | ---- | -------- | ------ |
| `small`  | 1    | 1024 MiB | 10 GiB |
| `medium` | 2    | 4096 MiB | 10 GiB |
| `large`  | 4    | 8192 MiB | 10 GiB |

```ts
import { createSandbox } from "@opencoredev/sandbox-sdk";
import { daytona } from "@opencoredev/sandbox-sdk/daytona";

await using box = await createSandbox(daytona(), {
  size: { cpu: 2, memoryMb: 8192, diskGb: 20 },
  network: { allow: ["registry.npmjs.org"] },
  idleTimeoutMs: 15 * 60_000,
  timeoutMs: 8 * 60 * 60_000,
});
```

- Exact sizes need whole CPUs, memory in whole GiB, and whole GiB of disk. A snapshot's disk can't shrink.
- Allow-list entries are plain DNS host names, with no scheme, port, or wildcard. An empty list blocks all traffic.
- `idleTimeoutMs` rounds up to the next minute and stops the sandbox, keeping its disk.
- `timeoutMs` rounds down to the minute, so the sandbox never outlives it. Under one minute fails with `unsupported`.

A stopped sandbox keeps its disk until Daytona archives it, after 7 days by default, and stays archived until you delete it. Two factory options change that, both rounded up to whole minutes:

```ts
import { createSandbox } from "@opencoredev/sandbox-sdk";
import { daytona } from "@opencoredev/sandbox-sdk/daytona";

const provider = daytona({
  autoArchiveMs: 24 * 60 * 60_000, // archive a day after it stops
  autoDeleteMs: 0, // or delete it as soon as it stops
});
await using box = await createSandbox(provider, { idleTimeoutMs: 15 * 60_000 });
```

## Volumes

To keep data across sandboxes, mount a [Daytona volume](https://www.daytona.io/docs/en/volumes) with the factory's `volumes` option. Every sandbox that provider creates mounts it. Each entry is `{ volumeId, mountPath, subpath? }`, the same shape as `VolumeMount` in Daytona's own SDK. `volumeId` takes the volume's ID or its name, and `subpath` mounts only that prefix of the volume instead of all of it.

The adapter doesn't create volumes, and a volume must be in the `ready` state before a sandbox can mount it. Create one in the Daytona Dashboard, with Daytona's own SDK, or through the factory's `api`, then read it back with `GET /volumes/{volumeId}` until its state is `ready`:

```ts
import { daytona } from "@opencoredev/sandbox-sdk/daytona";

const { api } = daytona();
const created = await api.request<{ id: string }>("POST", "/volumes", {
  body: { name: "my-volume" },
});
const volume = await api.request<{ state: string }>("GET", `/volumes/${created.id}`);
console.log(volume.state); // "ready" once it can be mounted
```

Then mount it:

```ts
import { createSandbox } from "@opencoredev/sandbox-sdk";
import { daytona } from "@opencoredev/sandbox-sdk/daytona";

const provider = daytona({
  volumes: [{ volumeId: "my-volume", mountPath: "/data", subpath: "user-123" }],
});

await using box = await createSandbox(provider);
await box.files.write("/data/notes.txt", "still here in the next sandbox\n");
```

## Configuration

| Option              | Type                                  | Default                      | Env var                   |
| ------------------- | ------------------------------------- | ---------------------------- | ------------------------- |
| `apiKey`            | `string`                              |                              | `DAYTONA_API_KEY`         |
| `jwtToken`          | `string`                              |                              | `DAYTONA_JWT_TOKEN`       |
| `organizationId`    | `string`                              |                              | `DAYTONA_ORGANIZATION_ID` |
| `baseUrl`           | `string`                              | `https://app.daytona.io/api` | `DAYTONA_API_URL`         |
| `target`            | `string`                              | `"us"`                       | `DAYTONA_TARGET`          |
| `image`             | `string`                              | Daytona's default snapshot   |                           |
| `snapshot`          | `string`                              | Daytona's default snapshot   |                           |
| `requestTimeoutMs`  | `number`                              | `30_000`                     |                           |
| `snapshotTimeoutMs` | `number`                              | `600_000`, at most `900_000` |                           |
| `createTimeoutMs`   | `number`                              | `60_000`                     |                           |
| `public`            | `boolean`                             | `false`                      |                           |
| `autoArchiveMs`     | `number`                              | Daytona's 7 days             |                           |
| `autoDeleteMs`      | `number`                              | Never                        |                           |
| `volumes`           | `{ volumeId, mountPath, subpath? }[]` |                              |                           |
| `outboundProxyUrl`  | `string`                              |                              |                           |

Set `image` or `snapshot`, not both. `from` overrides either. `apiUrl` is a deprecated alias for `baseUrl`. Use either `apiKey` or `jwtToken` with `organizationId`. `createTimeoutMs` covers the whole create call, including an image build. `outboundProxyUrl` routes the sandbox's HTTP(S) traffic through your proxy with `HTTP_PROXY` and `HTTPS_PROXY`. Daytona refuses it on tiers with restricted networking, and the create fails with `invalid_argument`. The image needs `sh`, `env`, `setsid`, `/bin/kill`, `python3`, and passwordless `sudo -n`.

## Call the API directly

`box.native` calls any Daytona endpoint the adapter doesn't wrap, with the adapter's credentials, retries, and error mapping. It has two planes:

| Plane             | Base URL                                     | What it serves                                                                                                      |
| ----------------- | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
| `"api"` (default) | `baseUrl`, `https://app.daytona.io/api`      | Sandboxes, snapshots, volumes, previews. `{sandboxId}` fills itself from the sandbox.                               |
| `"toolbox"`       | The sandbox's toolbox proxy URL, plus its ID | The sandbox's files and processes. Paths are already scoped to the sandbox, such as `/files` or `/process/execute`. |

`request` returns the JSON body. `fetch` returns the raw `Response`, for file bytes and streams.

```ts
import { createSandbox } from "@opencoredev/sandbox-sdk";
import { daytona } from "@opencoredev/sandbox-sdk/daytona";

await using box = await createSandbox(daytona());
const sandbox = await box.native.request<{ state: string; cpu: number }>(
  "GET",
  "/sandbox/{sandboxId}",
);
console.log(sandbox.state, sandbox.cpu);

const files = await box.native.request<{ name: string; isDir: boolean }[]>("GET", "/files", {
  plane: "toolbox",
  query: { path: "/workspace" },
});
console.log(files.map((file) => file.name));

const response = await box.native.fetch("GET", "/files/download", {
  plane: "toolbox",
  query: { path: "/workspace/report.csv" },
});
const bytes = new Uint8Array(await response.arrayBuffer());
```

For calls that aren't about one sandbox, use the factory's `api`. It has no sandbox bound, so pass `sandboxId` in `params` when a path needs one.

```ts
import { daytona } from "@opencoredev/sandbox-sdk/daytona";

const provider = daytona();
const snapshots = await provider.api.request<{ items: { name: string; state: string }[] }>(
  "GET",
  "/snapshots",
  { query: { limit: 20 } },
);
console.log(snapshots.items.map((snapshot) => snapshot.name));
```

To use the official SDK for something, install `@daytonaio/sdk` yourself and hand it to `sdk`. You get its `Sandbox` for this sandbox, or its `Daytona` client from `provider.api.sdk`, built with the adapter's credentials, `baseUrl`, and `target`.

```ts
import { createSandbox } from "@opencoredev/sandbox-sdk";
import { daytona } from "@opencoredev/sandbox-sdk/daytona";

await using box = await createSandbox(daytona());
const sandbox = await box.native.sdk(() => import("@daytonaio/sdk"));
const status = await sandbox.git.status("/workspace");
console.log(status.currentBranch);
```

In earlier betas, `box.native` was the SDK's `Sandbox` object. Replace `box.native.fs.listFiles(path)` and similar calls with `(await box.native.sdk(() => import("@daytonaio/sdk"))).fs.listFiles(path)`, or with `box.native.request`. See the [native API reference](/docs/reference/native).

## Limitations

- Keys are best-effort. Pass a [`locator`](/docs/concepts/sandboxes-and-keys#exact-and-best-effort-keys) for exact get-or-create.
- No pause, resume, or terminals.
- Timeouts are whole minutes.
- Previews need a header, so they can't go straight into an iframe.
- When a create fails after Daytona made the sandbox, such as a timeout while it starts or a `build_failed` image, the adapter deletes it before it reports the error. If the create request itself got no answer, the adapter looks for the sandbox by an internal label for about five seconds and deletes it. When it can't find it, the error is `outcome_unknown`: run [`reapSandboxes`](/docs/reference/sandbox) to clean up anything Daytona made late.

## How it works

- Keys and your `labels` become Daytona labels, so you can filter by them in the dashboard.
- With `image`, Daytona allocates the size at creation. From a snapshot, the adapter creates the sandbox, then stops, resizes, and restarts it before returning, which takes longer.
- Daytona's auto-pause is turned off, so an idle sandbox always stops.
- File reads and writes use the toolbox's multipart `bulk-download` and `bulk-upload` endpoints. Command output streams over plain HTTP from the session log endpoint.
- `DAYTONA_TARGET` picks a target. It doesn't set the organization's default region.

## Next steps

- [Processes and previews](/docs/concepts/processes-and-previews)
- [Machine size and network](/docs/guides/machine-size-and-network)
- [Daytona SDK and API in TypeScript](https://sandbox-sdk.app/blog/daytona-sdk-api-typescript): `@daytona/sdk`, the REST API and the toolbox next to `daytona()`
