---
title: Archil
seo:
  title: Archil Sandboxes SDK in TypeScript
description: Use Archil sandboxes from TypeScript through Archil's official disk SDK and one portable API. Exact keys, pause with memory, a terminal, network policies, sizes up to 32 vCPUs, and public previews.
---

`archil()` runs each sandbox as an Archil sandbox, a VM with its own root disk, through Archil's official TypeScript SDK, the `disk` npm package.

With `@opencoredev/sandbox-sdk` you call `createSandbox(archil())` and then `box.run`, `box.files`, `box.preview`, `box.pause` and `box.terminal`, and the same code runs on E2B or Modal when you swap the factory. Archil has no snapshots, templates or disk size through this API. The [capability matrix](/docs/reference/capabilities) lists what differs per provider, and [`box.native`](/docs/reference/native) gives you the `disk` `Sandbox` and `Archil` client when you need the rest.

## Install

**npm**

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

**pnpm**

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

**yarn**

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

**bun**

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

The adapter is written against `disk` 1.12.1 and accepts `^1.12.1`. Create an API key in the Archil console and set `ARCHIL_API_KEY`, or pass `archil({ apiKey })`. Keys belong to one region. For a key outside `aws-us-east-1`, the default, set `ARCHIL_REGION` or pass `region`: `aws-us-west-2` or `aws-eu-west-1` (Archil has no sandboxes in `gcp-us-central1`).

If you bundle your app, keep `disk` external. It loads its HTTP client, `undici`, with a computed `import()` the first time it sends a request, so a bundle that inlines `disk` can't find it. The adapter then fails with `unavailable` and says so.

## Quickstart

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

await using box = await createSandbox(archil(), { timeoutMs: 30 * 60_000 });
const result = await box.run("cat /etc/os-release");
console.log(result.stdout);
```

`await using` deletes the sandbox when the block ends. `timeoutMs` is Archil's maximum lifetime. When it runs out, Archil pauses the sandbox instead of deleting it, so a sandbox your process forgot stops using compute but keeps its disk until you delete it.

## What it supports

| Feature                        | Support | Notes                                                           |
| ------------------------------ | ------- | --------------------------------------------------------------- |
| Commands and streaming         | Yes     | Separate stdout and stderr, stdin, exit codes                   |
| Files                          | Yes     | Reads and writes need `python3`; the default image has it       |
| Background processes           | Yes     |                                                                 |
| Preview URLs                   | Yes     | Public `https://` URLs; no ports to declare                     |
| Pause and resume               | Yes     | Keeps memory and processes                                      |
| Snapshots                      | No      |                                                                 |
| Templates                      | No      | Use `image` or `imageId`                                        |
| Machine size                   | Partial | 1 to 32 vCPUs, 256 to 65536 MiB; no disk setting                |
| Network policy                 | Yes     | `"none"` and allow lists; paid plans only                       |
| Hard lifetime (`timeoutMs`)    | Yes     | 60 s to 24 h, whole seconds; pauses; not with ports or previews |
| Idle timeout (`idleTimeoutMs`) | Yes     | Whole seconds, up to 24 hours; pauses when it fires             |
| Keys                           | Exact   | Sandbox name is a hash of the key                               |
| Terminal                       | Yes     | A login shell as root with `TERM=xterm-256color`                |

## 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 { archil } from "@opencoredev/sandbox-sdk/archil";

await using box = await createSandbox(archil());
const result = await box.run("ls -la", { cwd: "/tmp", 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);
}
```

Commands run in `/workspace` unless you pass `cwd`. The default image is Archil's `node:24-bookworm`, Debian with glibc, Node.js 24 and `python3`. A timeout or abort kills the command's process tree and waits for Archil to confirm it ended; if Archil never confirms, the command fails with `outcome_unknown`.

## Pause, resume, and the idle timeout

`box.pause()` pauses the VM with its memory, and `box.resume()` brings it back with its processes where they were. A paused sandbox accrues no compute charge.

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

await using box = await createSandbox(archil(), { idleTimeoutMs: 10 * 60_000 });
await box.run("echo started > /workspace/state");
await box.pause();
await box.resume();
console.log((await box.run("cat /workspace/state")).stdout);
```

Archil pauses an idle sandbox by itself after 30 minutes, or after `idleTimeoutMs` when you pass one. A command on a paused sandbox fails with `unavailable` and a hint to call `box.resume()` first; the SDK never wakes one by itself, so a check such as `reapSandboxes` can't undo Archil's idle pause. `listSandboxes()` and `reapSandboxes()` leave out a paused or stopped sandbox: the file that proves it is the SDK's, with its key and labels, can't be read until it runs again, and a name alone is not proof. `connectSandbox(archil(), id)` still reaches it by ID, without waking it; its key and labels come back once it runs. Reopening it by `key` wakes it and checks the key. A paused sandbox accrues no compute charge, but its disk is billed until you delete it.

## Terminal

`box.terminal()` opens a PTY running a login shell as root.

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

await using box = await createSandbox(archil());
const terminal = await box.terminal({ cols: 120, rows: 30 });
terminal.onData((text) => process.stdout.write(text));
await terminal.write("uname -a\n");
await terminal.close();
```

## Previews

`box.preview(port)` exposes that port publicly and returns its `https://` URL. Nothing needs to be declared at creation, and anyone with the URL can open it. Traffic to a public port wakes a paused sandbox with a fresh lifetime, so a sandbox with a preview can't have a hard `timeoutMs`: use `idleTimeoutMs` to pause it when nobody is using it.

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

await using box = await createSandbox(archil(), { idleTimeoutMs: 30 * 60_000 });
await box.start("python3 -m http.server 8000", { name: "web", ready: { port: 8000 } });
const preview = await box.preview(8000);
console.log(preview.url);
```

## Size, network, and lifetime

| Preset   | vCPUs | Memory   |
| -------- | ----- | -------- |
| `small`  | 1     | 2048 MiB |
| `medium` | 2     | 4096 MiB |
| `large`  | 4     | 8192 MiB |

An exact `size` takes 1 to 32 whole vCPUs and 256 to 65536 MiB in whole MiB, such as `{ cpu: 8, memoryMb: 16384 }`. Anything outside that fails with `unsupported`. The root disk is about 1 TB and can't be changed, so `diskGb` fails with `unsupported`. Without `size`, Archil's default is 1 vCPU and 2048 MiB.

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

await using box = await createSandbox(archil(), {
  size: { cpu: 4, memoryMb: 8192 },
  network: { allow: ["registry.npmjs.org", "github.com"] },
  timeoutMs: 60 * 60_000,
});
```

`network: "none"` denies all outbound traffic, and `{ allow }` denies everything except the listed destinations. On Archil's free plan every sandbox already has outbound traffic denied, and a network policy fails with `unsupported` because the plan doesn't include it. Paid plans allow all outbound traffic unless you set a policy.

`timeoutMs` takes 60 seconds to 24 hours and rounds down to whole seconds, so the hard limit is never longer than you asked (24 hours becomes 23:59:59); `idleTimeoutMs` takes up to 24 hours and rounds up. A `timeoutMs` under a minute fails with `unsupported`. Both pause the sandbox when they fire. Because traffic to a public port resumes a paused sandbox with a fresh lifetime, `timeoutMs` with `ports`, or `box.preview()` on a sandbox created with `timeoutMs`, fails with `unsupported`.

## Limits and cost

Archil caps how many sandboxes run at once by plan: 5 on Free, 20 on Developer and 250 on Team. A create over the cap fails with `quota`. Compute is billed per vCPU-hour and GiB-hour while a sandbox runs; paused and stopped sandboxes accrue no compute, but the data on their disk is billed as storage until you delete them. See [Archil's billing docs](https://docs.archil.com/administration/billing.md) for current rates.

## Configuration

| Option    | Type                       | Default            | Env var          |
| --------- | -------------------------- | ------------------ | ---------------- |
| `apiKey`  | `string`                   |                    | `ARCHIL_API_KEY` |
| `region`  | `string`                   | `aws-us-east-1`    | `ARCHIL_REGION`  |
| `image`   | `string`, a public OCI ref | `node:24-bookworm` |                  |
| `imageId` | `string`                   | None               |                  |

`image` takes a public OCI image reference. `imageId` takes the ID of an image you built with Archil's image builds, and replaces `image` when both are set.

## Limitations

- No snapshots, snapshot restore (`from`) or templates.
- No disk size: the root disk is fixed.
- A network policy needs a paid plan; free-plan sandboxes have no outbound access.
- `timeoutMs` under 60 seconds fails, and an expired lifetime pauses the sandbox rather than deleting it.
- A paused or stopped sandbox is left out of `listSandboxes()` and `reapSandboxes()` until it runs again.
- A sandbox that failed at runtime keeps its name. Creating with its `key` fails with `unavailable` naming it; `connectSandbox(archil(), id)` then `destroy()` frees the key.

## How it works

- Every SDK sandbox is named `sbxsdk-` plus a UUID. A keyed sandbox is named `sbxsdk-k` plus 40 hex characters of the key's SHA-256. Archil names are unique per account, so the key is exact: concurrent creates with one key share one sandbox.
- Archil keeps no labels on a sandbox, so the adapter writes the key and your `labels` to `/var/lib/sandbox-sdk/metadata.json` inside it at create. `list` and `connect` read that file.
- Commands use Archil's process API over a WebSocket, which is why the adapter needs `disk` instead of calling `fetch`. Command input goes in 1 MiB pieces.
- A create that fails after Archil made the sandbox deletes it before failing. If the delete isn't confirmed, create fails with `outcome_unknown` and names the sandbox.
- `destroy()` stops and deletes within 2 minutes. If the sandbox wasn't stopped by then, it fails with `timeout` and the sandbox still exists; if a delete was sent but not confirmed, it fails with `outcome_unknown`, because Archil's client may still retry it.
- `box.native` returns `{ sandbox, client }`, the `disk` `Sandbox` and the `Archil` client that loaded it. Connect to the sandbox first.
- Errors keep only Archil's error name, HTTP status and error code, never its message, which can echo paths or commands.

## Next steps

- [Build an AI app builder](/docs/guides/build-an-ai-app-builder)
- [Machine size and network](/docs/guides/machine-size-and-network)
