> ## Documentation Index
> Fetch the complete documentation index at: /llms.txt
> Use this file to discover all available pages before exploring further.

# Sandboxes

> Run untrusted code behind a hardware boundary, with isolation you can dial up to airtight.

When an agent executes generated code, or you run something you pulled off the internet, you want the blast radius to end at a machine you can throw away. Every boxd machine is a KVM microVM with its own kernel, network stack, and disk. Code inside it has root over its own machine and no path to the host or to machines belonging to other tenants. The hypervisor boundary is the same one your laptop uses to run VMs.

<video autoPlay muted loop playsInline src="/videos/isolated-machine-2.mp4" />

An isolated machine boots like any other, in milliseconds.

![The task-1 machine row in the boxd console, with a red ISOLATED badge beside its green RUNNING status](/images/isolated-machine-row.png)

The console marks an isolated machine on its row.

## A real machine as the sandbox

Containers share the host's kernel, which is exactly the surface untrusted code attacks. A microVM gives the workload a kernel of its own, so the sandbox can allow everything a Linux server allows. Code in the sandbox can run Docker, load kernel modules, restart `systemd`, edit `/etc`, open ports, and break the OS completely, and the damage stays inside that one machine.

The trade-off you'd expect, slow VM startup, is gone. A fresh machine boots in under 10ms and a [fork](/guides/fork.md) lands in under 200ms, so per-task sandboxes feel like function calls.

## One sandbox per task

Create a machine, run the untrusted work, delete it:

> [tab] CLI
>
> ```bash
> boxd machine new task-1 --isolated
> boxd machine exec task-1 -- 'python3 generated_script.py'
> boxd machine remove task-1 -y
> ```

> [tab] TypeScript
>
> ```typescript
> import { Boxd } from "@boxd-sh/sdk";
>
> const boxd = new Boxd();                    // reads BOXD_API_KEY
> const machine = await boxd.machines.create({ name: "task-1", isolated: true });
> await boxd.machines.waitUntilReady(machine.id);
>
> const result = await boxd.machines.exec(machine.id, {
>   command: ["python3", "generated_script.py"],
> });
> console.log(result.stdout);
>
> await boxd.machines.delete(machine.id);
> ```

> [tab] Python
>
> ```python
> from boxd import Boxd
>
> boxd = Boxd()                          # reads BOXD_API_KEY
> machine = boxd.machines.create("task-1", isolated=True)
> boxd.machines.wait_until_ready(machine.id)
>
> result = boxd.machines.exec(machine.id, "python3 generated_script.py")
> print(result.stdout)
>
> boxd.machines.delete(machine.id)
> ```

For longer sessions, keep the sandbox and let it sleep between uses. A machine on standby resumes in sub-millisecond time with its filesystem and processes intact. See [Suspend, resume, and hibernate](/guides/suspend-resume.md).

## Fleets for automation

Background jobs, runners, test matrices, agent fleets, and [RL rollouts](/use-cases/reproducible-rl-environments.md) all want many disposable environments at once. Create them concurrently, and every one is hardware-isolated from the others and from the rest of your machines:

> [tab] TypeScript
>
> ```typescript
> import { Boxd } from "@boxd-sh/sdk";
>
> const boxd = new Boxd();   // reads BOXD_API_KEY
>
> const names = Array.from({ length: 15 }, (_, i) => `sandbox-${i + 1}`);
>
> const machines = await Promise.all(
>   names.map(async (name) => {
>     const machine = await boxd.machines.create({ name, isolated: true });
>     await boxd.machines.waitUntilReady(machine.id);
>     return machine;
>   })
> );
>
> console.log(`${machines.length} isolated sandboxes up`);
> await boxd.close();
> ```

> [tab] Python
>
> ```python
> from concurrent.futures import ThreadPoolExecutor
> from boxd import Boxd
>
> boxd = Boxd()   # reads BOXD_API_KEY
>
> def sandbox(i: int):
>     machine = boxd.machines.create(f"sandbox-{i}", isolated=True)
>     boxd.machines.wait_until_ready(machine.id)
>     return machine
>
> with ThreadPoolExecutor(max_workers=15) as pool:
>     machines = list(pool.map(sandbox, range(1, 16)))
>
> print(f"{len(machines)} isolated sandboxes up")
> ```

These boot the default Ubuntu image. To start every sandbox with your own toolchain, dependencies, and services already in place, create them from a [snapshot](/guides/snapshots.md) instead, with `fromSnapshot: "my-toolchain"` / `from_snapshot="my-toolchain"` alongside the same `isolated` flag. A fresh machine boots in under 10ms, so the fleet is up in seconds.

Disposable is one mode, and persistent is the other. boxd machines are persistent by default. A sandbox lives as long as you keep it, disk and all, which is exactly what a multi-tenant product wants: one long-lived isolated machine per customer. See [Agentic SaaS](/use-cases/agentic-saas.md).

> [!TIP]
>
> The default cap is 50 machines per organization, so this fleet fits with room to spare. Need more? Raises for real workloads are usually same-day via [contact@boxd.sh](mailto:contact@boxd.sh). See [Resources and limits](/guides/resources.md).

## Cut off from your fleet by design

Normally, machines you own share one private network, and each carries a pre-authenticated in-machine `boxd` CLI. That is convenient for your own machines and wrong for a sandbox, because code in the sandbox could reach your other machines.

A sandbox created with `--isolated` is cut off from all of that from birth. boxd leaves out everything that could reach into the rest of your organization: the in-machine boxd CLI, your integrations and the run CLI, your agent logins, and the bridge to your laptop. It never joins the default network and never reaches another isolated machine. It keeps outbound internet unless you set an [egress allowlist](/guides/egress), along with its public HTTPS domain, inbound SSH unless you [turn it off](/cli/commands.md#turn-ssh-off), and its persistent disk, so it is a normal machine to work in that cannot see or act on anything else you own.

When a sandbox does need a controlled path to something of yours, a job queue or a shared database for example, grant it one explicitly with [networks](/guides/vm-to-vm.md#networks). An isolated machine reaches exactly the non-isolated machines it shares a named network with, and networking changes apply in real time, without a reboot:

```bash
boxd machine networks scratch jobs     # grant access to machines on `jobs`, effective immediately
boxd machine networks scratch --clear  # cut it off again
```

> [!NOTE]
>
> `--isolated` is set at creation and cannot be changed afterward. Forks and machines created from its snapshots inherit it, so an isolated lineage stays isolated.

## Close the internet and SSH too

Isolation cuts a sandbox off from your fleet. For code you trust even less, close the other two ways in and out as well: an [egress allowlist](/guides/egress-allowlist.md) that names only what the sandbox needs (`none` for nothing at all), and SSH off, so nothing answers SSH for it. You drive the sandbox through `exec` and file transfers, which go through the boxd API and keep working.

> [tab] CLI
>
> ```bash
> boxd machine new task-1 --isolated --no-ssh
> boxd machine egress task-1 proxy.example.com    # or `none` for no internet at all
> ```

> [tab] TypeScript
>
> ```typescript
> import { Machine } from "@boxd-sh/sdk";
>
> const spec = Machine.spec().isolated().egress("proxy.example.com");
> const machine = await boxd.machines.create({ name: "task-1", spec, config: { ssh: false } });
> ```

> [tab] Python
>
> ```python
> from boxd import Machine
>
> spec = Machine.spec().isolated().egress("proxy.example.com")
> machine = boxd.machines.create("task-1", spec=spec, ssh=False)
> ```

With a spec, the allowlist is in force from the machine's first boot. DNS follows it too: a lookup of a name the sandbox may not reach is refused, so a lookup can't carry data out.

## FAQ

> [accordion] What stops code from breaking out of the sandbox?
>
> The microVM boundary. Code has root inside its own machine and no path to the host or to other machines. Internet egress is the only shared surface, and it can be confined to an [allowlist](/guides/egress); `--isolated` removes the paths into your own fleet as well.

> [accordion] How many sandboxes can I run at once?
>
> The default cap is 50 machines per organization, and you can request a raise beyond that, usually granted same-day. See [Resources and limits](/guides/resources.md).

> [accordion] Can sandboxed code run Docker?
>
> Yes. The machine has a real kernel and a real `systemd`, so Docker works without nesting tricks. See [Run Docker](/guides/run-docker.md).
