> For AI agents: the complete documentation index is available at https://enclo.nstlopez.com/llms.txt, the full documentation bundle is available at https://enclo.nstlopez.com/llms-full.txt.

# Sandboxes

Each sandbox has a private disk image under `~/.enclo` and, when running, a
libkrun microVM booted from that disk. The guest runs Alpine Linux 3.24.4
matching your host architecture, and commands execute as root.

## The session's sandbox

Each agent session gets one default sandbox, created on the first tool call and
kept after the session ends. The agent does not need to call `create` first:
`run`, `push`, `write_file`, and the other tools target the session's sandbox
whenever the `sandbox` argument is omitted.

To work with additional sandboxes, the agent can call `create` (either empty or
cloned from an existing sandbox's disk) and pass the returned ID as the
`sandbox` argument to other tools.

## Starting and stopping

The first command boots the sandbox (about 0.2 s on Apple silicon) and leaves
it running. Subsequent commands start immediately, and multiple commands can
run in parallel.

A sandbox shuts down automatically after 15 minutes with no command running,
even if a background server is still listening. The next command boots it
again.

|                              | Running   | Shut down |
| ---------------------------- | --------- | --------- |
| Files and installed packages | Kept      | Kept      |
| Background processes         | Running   | Stopped   |
| Host memory                  | Allocated | Freed     |

The MCP `stop` tool (or `enclo kill` in the CLI) terminates a running command
while leaving the sandbox running. The MCP `shutdown` tool (or `enclo stop`)
powers off the sandbox while keeping its disk.

If a command times out, enclo terminates that command while the sandbox
continues running with its files and other processes intact.

## Long commands

Each `run` call waits up to 45 seconds. If the command is still running, `run`
returns an `exec_id`. Calling `run` again with that `exec_id` waits up to
another 45 seconds and returns any output produced since the previous call. The
command itself runs until it finishes or hits its timeout (600 seconds by
default, up to 3600 seconds).

## Servers in a sandbox

You can start a server in the background and talk to it from later commands:

```sh
nohup python3 -m http.server 8000 > /tmp/server.log 2>&1 &
```

Any output a background process writes after the starting command returns is
discarded unless redirected to a file, as shown above.

:::tip localhost resolves to IPv6 first
Inside the guest, `localhost` resolves to `::1` first. If a server listens
only on IPv4, connect to `127.0.0.1` instead.
:::

The 15-minute idle timeout still applies because it tracks active commands
rather than open network connections. Use `enclo new --idle-timeout 0` to
create a sandbox that stays running until you stop it.

## Files in and out

No host directory is shared with a sandbox.

| Direction                  | MCP tools                                    | Command line                  |
| -------------------------- | -------------------------------------------- | ----------------------------- |
| Copy a project in          | `push` (skips files matched by `.gitignore`) | `enclo push`                  |
| Write a single file        | `write_file` (text, up to 5 MiB)             | `enclo push` on its directory |
| Download from the internet | `run` with `git clone`, `curl`, or `apk add` | `enclo exec`                  |
| Read results back          | Command output or `read_file`                | `enclo pull`                  |

The MCP tools cannot write files to your host machine. `read_file` returns text
by default, or the raw bytes of any file when called with `encoding: "base64"`.

## Start every session from a prepared sandbox

New session sandboxes start empty unless you configure a base sandbox. Create a
sandbox once, install the tools your projects need, and set `session.base` to
its name:

```sh
enclo new --name base
enclo exec base "apk add git nodejs npm python3"
enclo config set session.base base
```

Every new session sandbox will start as a copy of that disk. The base sandbox
must exist; if you delete it, tool calls report the missing base. Run
`enclo config unset session.base` to go back to starting from empty sandboxes.

## Size

By default, each sandbox gets 2 vCPUs, 2048 MiB of memory, and a 64 GiB sparse
disk (using about 5.5 MB on disk when empty). A single sandbox is capped at
your host's core count for vCPUs and half of host memory.

See [Configuration](https://enclo.nstlopez.com/reference/configuration.md) to change these defaults. Each
running sandbox holds its allocated memory until it shuts down, and enclo does
not prevent you from starting sandboxes whose combined memory exceeds what your
host has. Run `enclo stop --all` to shut down all running sandboxes.

## Cleanup

The MCP `list` and `remove` tools only see sandboxes created through MCP. At
the start of a harness session, `enclo mcp` removes unnamed MCP sandboxes that
have not been used in 14 days. Run `enclo prune` to do this manually, or
`enclo rm --all` to delete all sandboxes. You can change the 14-day window with
`prune.older_than` in [Configuration](https://enclo.nstlopez.com/reference/configuration.md).
