# Isolation tiers

Each sandbox runs on one isolation tier, from confined processes on the host's kernel to a virtual
machine with its own kernel. A request that names a tier gets it, or a refusal that says what is
missing.

| Tier | Runs | Separates a sandbox with | Kernel | Needs from the host |
| --- | --- | --- | --- | --- |
| `process` | Native commands on a bundled userland | Landlock, seccomp and rlimits; namespaces and a cgroup of its own where the host allows | The host's | Linux with Landlock ABI 3 (6.2 or later); no root |
| `wasm` | WebAssembly, Python and JavaScript, agentOS packages | A virtual kernel in a shared, unprivileged agentOS sidecar | A virtual kernel per sandbox | `x86_64`; no root |
| `container` | Any image the host allows | Namespaces, cgroups, every capability dropped | The host's | Docker or Podman |
| `gvisor` | Any image the host allows | The container tier's settings, under gVisor's `runsc` | gVisor's user-space kernel | Docker with `runsc`, which the server preset installs |
| `vm` | `linux/amd64` images | A Firecracker virtual machine under KVM | Its own Linux kernel | `x86_64` with KVM the daemon's user can open |

Only `vm` boots its own kernel. By default a node serves every tier its measured host capabilities
allow, side by side, and `hermitbox doctor` lists the tiers it serves and why the others are off.

## Process tier

The `process` tier runs each sandbox as confined Linux processes, with no host privilege. Landlock
keeps it out of other sandboxes' data and `/proc`, and a seccomp filter denies mounts, `ptrace`,
namespace creation, `bpf` and identity changes.

What else it gets depends on the host:

- **Namespaces:** where user namespaces work, each sandbox gets its own PID and IPC namespaces, a
  private `/tmp`, and an empty network for `network: 'none'`.
- **Limits:** where cgroup controllers are delegated to `hermitboxd`, the kernel enforces memory and
  CPU limits. Elsewhere memory is a sampled budget, not a hard cap.
- **Users:** as root, each sandbox gets its own UID once the host's credential-drop probe passes.
  As an ordinary user, sandboxes share yours.
- **Network:** with kernel network policy, eBPF programs decide each destination. Without it,
  internet-enabled process sandboxes share the host's network and must trust each other.

The [process isolation](https://docs.hermitbox.dev/v0.2.1/reference/process-tier.md) reference covers each mode.

## Wasm tier

The `wasm` tier runs software built for WebAssembly inside agentOS's virtual kernel. All wasm
sandboxes on a node share one sidecar, so they share a fault domain and its CPU. Ingress is HTTP
over TCP, hostname egress is refused, and sleep keeps data but not processes. See
[agentOS on Hermitbox](https://docs.hermitbox.dev/v0.2.1/integrations/agentos.md).

## Container and gVisor

The `container` tier runs images through Docker or Podman, with every capability dropped,
`no-new-privileges`, private IPC and a PID limit. Images come only from the host's allowed
prefixes. Containers share the host's kernel.

The `gvisor` tier is the same engine, images, limits and firewall, with gVisor's `runsc` as the
runtime. Each sandbox's system calls go to gVisor's user-space kernel, not the host's. They cost
more: one-byte reads and writes cost about 26 times what they cost in a container. Hostname egress
is refused on this tier.

## Virtual machine tier

The `vm` tier boots each sandbox in a Firecracker virtual machine with its own Linux kernel. It
needs an image, and as an ordinary user it can sleep with memory. See
[Virtual machines](https://docs.hermitbox.dev/v0.2.1/guides/virtual-machines.md) for what a host needs and how images become disks.

## How the default is chosen

When a request names no tier, control tries `container`, `vm`, `gvisor`, `process` and `wasm`, in
that order, keeping only the tiers that fit the source:

- An `image` runs on `container`, `vm` or `gvisor`.
- No image runs on `process` or `wasm`.
- `packages` runs on `wasm`.

The first tier that a healthy node serves, with the guarantees in `require`, wins. A snapshot or a
template keeps the tier it was saved on. The operator can fix one tier, or change the order, with
`HERMITBOX_DEFAULT_ISOLATION=process` or a comma-separated list.

```ts
// Ask for a container from an image.
const box = await hb.sandbox({
  isolation: 'container',
  image: 'alpine:3.22',
})

console.log(box.isolation) // container
```

```python
# Ask for a container from an image.
box = hb.sandbox(
    isolation='container',
    image='alpine:3.22',
)

print(box.isolation)  # container
```

The chosen tier is stored before compute starts and never changes for the life of the sandbox.

## Never a weaker guarantee

A tier you name is never swapped for another. A `container` request never runs on `runsc`, and a
`gvisor` request never runs without it. When no healthy node serves the tier, creation answers 503
`no_room`:

```txt
No node can serve the vm tier for this request
```

The same holds for guarantees. Each sandbox reports `guarantees`, such as `own-kernel`,
`memory-limit`, `private-network` and `host-firewall`, and a guarantee its node doesn't announce
reads `false`. A create can `require` any of them, and a wake checks them again:

```ts
// Place this sandbox only where memory limits are enforced.
const box = await hb.sandbox({
  image: 'alpine:3.22',
  require: ['memory-limit'],
})
```

```python
# Place this sandbox only where memory limits are enforced.
box = hb.sandbox(
    image='alpine:3.22',
    require=['memory-limit'],
)
```

A request can't loosen the host's policy. Capabilities, mounts, images, users and network rules
come from the host's configuration, and `HERMITBOX_REQUIRE` adds requirements no request can remove.

## Next steps

- [Sandbox tiers](https://docs.hermitbox.dev/v0.2.1/reference/tiers.md): measurements and a full comparison.
- [Capabilities](https://docs.hermitbox.dev/v0.2.1/reference/capabilities.md): which tiers give which guarantees.
- [Host capabilities and guarantees](https://docs.hermitbox.dev/v0.2.1/reference/host-capabilities.md): what the host probe checks.
