# Configuration (https://kumoba.dev/configuration)

kumoba works without configuration. Each setting below overrides one default.

## Daemon (`kumobad`) [#daemon-kumobad]

Set these in kumobad's environment. `kumobad --help` prints the same list.

| Variable | Default | Meaning |
| --- | --- | --- |
| `KUMOBA_HOME` | `~/.kumoba` | Base directory for the defaults below |
| `KUMOBAD_IMAGES` | every `$KUMOBA_HOME/images/*.raw` | Images to serve, as `name=/path/to/image.raw,...` |
| `KUMOBAD_STATE_DIR` | `$KUMOBA_HOME/state` | Sandbox disks, metadata and keys |
| `KUMOBAD_TOKEN_FILE` | `$KUMOBA_HOME/token`, created on first start | Bearer token, 32 bytes or more |
| `KUMOBAD_TOKEN_FILE_NEXT` | none | A second bearer token, accepted beside the first while clients switch to it. A missing file means no second token |
| `KUMOBAD_WORKER` | next to `kumobad` | The `kumoba-worker` binary |
| `KUMOBAD_MACOS_AGENT` | `kumoba-guest-macos` next to `kumobad` | The guest agent `kumobad macos-image` installs into a macOS image |
| `KUMOBAD_VIEW` | `kumoba-view-host` next to `kumobad` | The live view engine `kumobad` starts for a macOS sandbox's desktop link |
| `KUMOBAD_SOCKET` | `$KUMOBA_HOME/kumobad.sock` unless `KUMOBAD_LISTEN` is set | Unix socket for the API, mode 0600 |
| `KUMOBAD_LISTEN` | `127.0.0.1:7788` when neither it nor `KUMOBAD_SOCKET` is set | `host:port` for the API. An address other than loopback needs TLS |
| `KUMOBAD_PREVIEW_LISTEN` | `127.0.0.1:7789` when nothing else is set | `host:port` that serves previews and the desktop to browsers. An address other than loopback needs TLS |
| `KUMOBAD_PREVIEW_URL` | `http://<preview listen address>`, `https://` with TLS | Base URL browsers reach that listener at, behind a reverse proxy or another host name. Required when the preview listener is on `0.0.0.0` or `[::]` |
| `KUMOBAD_TLS_CERT` | none | PEM certificate chain. With `KUMOBAD_TLS_KEY`, both TCP listeners speak TLS; the Unix socket stays plain. See [Run sandboxes on another machine](/guide/remote-daemon) |
| `KUMOBAD_TLS_KEY` | none | PEM private key of that certificate |
| `KUMOBAD_TLS_CLIENT_CA` | none | PEM CA certificates. The API listener then accepts only clients with a certificate one of them signed (mutual TLS). The token is still required, and previews take no client certificate |
| `KUMOBAD_MAX_RUNNING` | `4` | Sandboxes running or booting at once: a whole number from 1 to 1024, or `auto` to size it from memory and CPUs (below). Any other value stops kumobad at startup. A create with `start`, and `/v1/run`, take a slot before they copy the disk and answer 429 `capacity` at once when none is free; `GET /v1/capacity` reads the count |
| `KUMOBAD_RESERVED_MEMORY_MIB` | `2048` | Memory in MiB that `auto` and `KUMOBAD_ADMIT_BY_MEMORY` leave to the host and kumobad itself |
| `KUMOBAD_SANDBOX_MEMORY_MIB` | `4096`, what a create gets without `memoryMib` | Memory in MiB of the sandbox that `auto` sizes the limit for, 256 to 16384 like a create |
| `KUMOBAD_SANDBOX_CPUS` | `2`, what a create gets without `cpu` | vCPUs of the sandbox that `auto` sizes the limit for, 1 to 8 like a create. Any other value stops kumobad at startup |
| `KUMOBAD_MIN_FREE_DISK_MIB` | `1024` | Free disk in MiB, in the state directory's filesystem, that a create must leave (below). `0` refuses only a copy that cannot fit at all. Not a whole number stops kumobad at startup |
| `KUMOBAD_PRUNE_STOPPED_ON_DISK_PRESSURE_MS` | off | Milliseconds. A create that would cut into `KUMOBAD_MIN_FREE_DISK_MIB` first deletes stopped sandboxes that stopped at least this long ago, oldest first, until it fits (below). `0` takes any stopped sandbox. Not a whole number stops kumobad at startup |
| `KUMOBAD_ADMIT_BY_MEMORY` | `0` | `1` admits sandboxes by the memory they ask for as well as by count (below). Any other value stops kumobad at startup |
| `KUMOBAD_HOST_LABELS` | none | `key=value[,key2=value2]` labels `GET /v1/info` reports for this host, for clients that place sandboxes across hosts. A key follows the sandbox label rules (not empty, no `:`); a malformed entry or a key set twice stops kumobad at startup |
| `KUMOBAD_DISK_MODE` | `auto` | How a sandbox gets its disk. `auto` gives each sandbox a copy-on-write layer over a shared copy of the image on a Mac and on Linux filesystems that can't clone files, and a clone of that shared copy on XFS and Btrfs (see [Disks](/architecture#disks)). `copy` makes a full copy for every sandbox, as kumobad 0.10 did. Any other value stops kumobad at startup |
| `KUMOBAD_DRAIN_ON_START` | `0` | `1` starts kumobad [draining](/http-api#drain): it creates no sandboxes until `DELETE /v1/drain` (`kumoba undrain`). `strict` also refuses to start stopped sandboxes. Any other value stops kumobad at startup. Without it a restart ends a drain |
| `KUMOBAD_ALLOW_PRIVATE_HOSTS` | none | Intranet host names and IPv4 or IPv6 CIDRs sandboxes may reach, on ports 80 and 443 unless an entry adds `:port` or `:*` (`10.20.0.0/16:5432`, `[2600:1f18:abcd::/56]:*`). IPv6 entries always go in brackets. IPv6 destinations are reachable only through an entry here. A range does not bypass the upstream proxy |
| `KUMOBAD_UPSTREAM_PROXY` | none | `http://[user:pass@]host[:port]` proxy for outbound traffic |
| `KUMOBAD_NO_PROXY` | none | Host names, and IP addresses for connections to an address, reached directly instead of through the proxy |
| `KUMOBAD_UPSTREAM_PROXY_CONNECT` | `address` | What the proxy `CONNECT` names: the checked `address`, or the `host` name |
| `KUMOBAD_LIBKRUN`, `KUMOBAD_LIBKRUNFW` | `../lib` next to `kumobad`, then the system | libkrun and its firmware |

With `KUMOBAD_MAX_RUNNING=auto`, kumobad computes the limit once at startup: the host's memory, less `KUMOBAD_RESERVED_MEMORY_MIB`, divided by `KUMOBAD_SANDBOX_MEMORY_MIB`, or the host's CPUs divided by `KUMOBAD_SANDBOX_CPUS`, whichever is fewer, rounded down, at least 1 and at most 1024. With the defaults an 8-CPU, 16 GiB host runs 3 sandboxes, and a 4-CPU one runs 2; with `KUMOBAD_SANDBOX_MEMORY_MIB=8192` a 64 GiB host runs 7 with 16 CPUs, but 2 with 4 CPUs. To let sandboxes share CPUs, set `KUMOBAD_SANDBOX_CPUS=1` (the 4-CPU, 64 GiB host then runs 4 sandboxes of 2 vCPUs each) or a number in `KUMOBAD_MAX_RUNNING`. CPUs here are logical CPUs as the OS lists them, so each hyperthread counts as one, and only those kumobad may run on (its CPU affinity on Linux) count. On Linux, a cgroup memory limit on kumobad or a parent cgroup (systemd `MemoryMax=`, a container's memory limit) counts instead when it is lower than the host's memory, and a cgroup CPU quota (systemd `CPUQuota=`, a container's `--cpus`) counts as that many CPUs, rounded down and at least 1, when it is lower. kumobad reads cgroup limits only under `/sys/fs/cgroup`; where cgroupfs is mounted elsewhere or not at all, `auto` counts the whole host, so set a number instead. When the memory left after the reserve is smaller than one sandbox, the limit is still 1 and kumobad logs `max_running_short_of_memory` at startup; when the CPUs are fewer than `KUMOBAD_SANDBOX_CPUS`, it likewise logs `max_running_short_of_cpus`. Without `KUMOBAD_ADMIT_BY_MEMORY`, kumobad does not check memory when a sandbox boots, so creates that ask for more `memoryMib` than the reference size can still use more than the host has. The `ready` log line and `GET /v1/capacity` show the limit and how it was derived. macOS sandboxes keep their own limit of 2.

With `KUMOBAD_ADMIT_BY_MEMORY=1`, kumobad also adds up the memory of the sandboxes that run, boot or hold a slot. A start, a create with `start` and `/v1/run` are admitted only while that sum plus the new sandbox's memory stays within the budget: the host's memory (or the lower cgroup limit, as `auto` counts it) less `KUMOBAD_RESERVED_MEMORY_MIB`. Otherwise they answer 429 `capacity` at once, before any disk is copied, just as at the count limit, which still applies. On a 16 GiB host with the default 2 GiB reserve, the budget is 14336 MiB: two 4 GiB sandboxes and one 6 GiB sandbox run, and a further 4 GiB create gets 429. A macOS sandbox counts the memory its image's `machine.json` sets. A sandbox that asks for more than the whole budget can never run on the host, so a create (with or without `start`), a start or a run for it answers 422 `exceeds_host_memory` at once, even with `waitMs`; retrying does not help, but a bigger host can take it. When the budget is smaller than the smallest sandbox (256 MiB), kumobad stops at startup. Leave `KUMOBAD_MAX_RUNNING` at a count that suits the host's CPUs, or use `auto`, which caps it by CPUs; the default of 4 still caps the number. kumobad reads the budget once at startup; the `ready` log line carries it under `memoryBudget`, and `GET /v1/capacity` reports `memoryMibInUse` and `memoryMibBudget`.

Requests that wait (`waitMs`) are served in the order they asked. A request that is short of memory or of a running slot holds back every request behind it, even smaller ones that would fit, so a large sandbox is never passed over indefinitely; a request with no wait is refused while one ahead of it waits for the same thing. A macOS sandbox that waits only for one of the two macOS slots holds back other macOS sandboxes, not Linux ones.

Before a create, a create with `start` or `/v1/run` copies the image's disk, kumobad works out how much disk the copy needs and refuses it with 507 `disk_full` when the free space in the state directory's filesystem, less what copies still in progress have left to write, would drop below `KUMOBAD_MIN_FREE_DISK_MIB`. Nothing is written for a refused create. A copy that the filesystem can clone (reflinks on Btrfs or XFS, APFS clones on a Mac) needs no space; on other filesystems it needs what the image holds: its allocated blocks on Linux, its full size on a Mac. kumobad tests at startup whether the state directory can clone, and tests again on the next create when that test could not run (for instance because the disk was full). When a clone it counted on fails anyway (a source on another filesystem behind a bind mount), kumobad counts the full size before it falls back to copying, and answers 507 if that does not fit. When the free space cannot be read, creates go ahead with `KUMOBAD_MIN_FREE_DISK_MIB=0` and are refused with 500 otherwise, and kumobad logs `disk_space_unreadable` once, and `disk_space_readable` when it can read it again. The default of 1024 MiB keeps kumobad from filling the disk to the last byte, where its own state writes (sandbox records, the event log) would start to fail. Running sandboxes write to their disks too, so on a busy host raise it: a few GiB per running sandbox is a reasonable start. Even with `0`, kumobad refuses a copy that cannot fit at all, which would otherwise fail part way with `No space left on device`. `GET /v1/capacity` and `GET /v1/info` report the free and total bytes, the bytes stopped sandboxes hold and this minimum under `disk`, and [`POST /v1/sandboxes/prune-stopped`](/http-api#prune-stopped-sandboxes) deletes old stopped sandboxes to free space.

With `KUMOBAD_PRUNE_STOPPED_ON_DISK_PRESSURE_MS` set, kumobad does that prune itself instead of answering 507: a create, a create with `start` or `/v1/run` that would cut into the minimum deletes stopped sandboxes that stopped at least that many milliseconds ago, oldest first, one at a time, and tries the create again after each, so it deletes only until the create fits. A sandbox that never started counts from when it was created, so with `0` one created a moment ago and not started yet can go. A sandbox that came in through an import or a fleet move counts from its arrival, not from when it stopped on the other host. It follows the prune's rules: running and booting sandboxes, those busy with another call (an export or a move among them), and a create with `start` or a `/v1/run` that has not answered yet stay. Creates that need room wait for each other, so two of them never delete for the same space. Each deleted sandbox gets a `deleted` event with `"reason": "disk_pressure"`, and kumobad logs `disk_pressure_pruned` with the `sandboxId` and `freedBytes`, the free space it measured before and after the delete.

It deletes as little as it can, but it cannot know what a delete frees until it measures, so a create can delete one sandbox and still answer 507 `disk_full`. kumobad deletes none when the bytes the remaining sandboxes hold, scaled by the share of their size that its deletes since it started really freed, could not make room. It stops after a delete that freed less than half the sandbox's size while the create is still short. Each delete counts as freeing at most that sandbox's size, so space freed elsewhere at the same moment does not make deletes look more useful than they are. After a create that deleted something and still did not fit, creates answer 507 without deleting for 60 seconds, or until the free space grows. Where a sandbox's disk is a clone (on Btrfs, on XFS with reflinks, for macOS sandboxes, and for sandboxes kumobad 0.15 or earlier made on a Mac) it frees only the blocks it no longer shares with its image, so `freedBytes` can be far less than its `stoppedSandboxBytes`; there the first delete that frees almost nothing ends the pruning. It deletes your data without a call, so it is off unless set; pick an age past which nobody will start a stopped sandbox again. Under a [fleet](/guide/fleet), a create goes first to hosts that report free disk above their minimum, and each host with the setting prunes on its own only when the create lands on it full.

On `SIGHUP`, kumobad re-reads the TLS certificate, key and client CA and both token files, without stopping sandboxes or open connections. If a file fails to load, kumobad keeps the old certificates or tokens and logs `tls_reloaded` or `token_reloaded` with `"ok": false` and the reason. Other settings are read only at startup. See [Rotate certificates and tokens](/guide/remote-daemon#rotate-certificates-and-tokens).

`kumobad host init [--address <name-or-ip>]... [--force]` writes a server certificate, a client CA and `host.json` to `$KUMOBA_HOME/tls/` and prints a pairing code; `kumobad host pair-code` prints another. While `KUMOBAD_TLS_CERT`, `KUMOBAD_TLS_KEY` and `KUMOBAD_TLS_CLIENT_CA` are all unset and that `host.json` exists, kumobad serves those files with client certificates required, listens on `0.0.0.0:7788` and `0.0.0.0:7789` unless `KUMOBAD_LISTEN` and `KUMOBAD_PREVIEW_LISTEN` are set, and accepts `POST /v1/pair`. See [Set up a host for a fleet](/guide/remote-daemon#set-up-a-host-for-a-fleet).

Each listener (the Unix socket, the API and the preview listener) serves at most an eighth of kumobad's open-file limit in connections at once, between 8 and 1024, so a flood on one listener leaves the others and the files sandboxes need alone. kumobad raises its soft open-file limit to the hard limit at startup; raise the hard limit (`ulimit -Hn`, or `LimitNOFILE=` in a systemd unit) for more. A shell, live view or WebSocket holds its connection until it closes, and further connections wait until one closes. While a listener is full, kumobad logs `connections_full` with the listener (`socket`, `api` or `preview`) and its limit, at most once every 10 s. TCP connections send keepalive probes after 60 s of silence and are closed when 4 probes 15 s apart get no answer, so a client that vanished without closing its connection gives up its slot. A client has 30 s to send a request's headers, a connection with no request in progress is closed after 30 s, and a TLS handshake must finish within 10 s.

### Log lines [#log-lines]

kumobad and `kumobad fleet` log to stderr, one JSON object per line, such as `{"error":null,"event":"auto_stop","level":"info","sandboxId":"...","type":"kumobad"}`. Every line has `"type": "kumobad"`, an `event` and a `level`:

| `level` | Meaning | Events |
| --- | --- | --- |
| `error` | kumobad failed to do something | `fatal` (kumobad could not start), a failed reload, `pair_failed`, `fleet_hosts_unreadable`, and any other event that carries an `error`, such as `meta_persist_failed`, `meta_restore_failed` or a failed `auto_stop` |
| `warn` | kumobad carries on, but something needs a look, such as a client it refused | `tls_refused`, `network_reconciled` (a sandbox took the network its saved settings name at start), `listen_skipped`, `preview_listen_skipped`, `connections_full`, `pair_refused`, `token_file_readable`, `fleet_key_readable`, `max_running_short_of_memory`, `max_running_short_of_cpus`, `shutdown_deadline`, and `fleet_host` for a host that turned `unhealthy` or `refused` |
| `info` | Routine | `ready`, `fleet_ready`, `drain`, `paired`, a successful reload, `fleet_host` for a host that is `active` or `draining`, and sandbox events such as `auto_stop` or `disk_pressure_pruned` without an `error` |

A line with an `error` that is not null is never `info`: it is `error`, or `warn` when kumobad carries on and the cause is usually outside it, such as a client that failed the TLS handshake or a default port already in use. A supervisor can filter on `level` instead of reading every line from stderr as an error. When `kumobad` or `kumobad fleet` cannot start, the reason is a `fatal` line too, not plain text. Commands that print for a person, such as `kumobad host init` and `kumobad fleet add`, still write plain text.

## Clients (CLI and SDK) [#clients-cli-and-sdk]

| Variable | Default | Meaning |
| --- | --- | --- |
| `KUMOBA_URL` | `unix://$KUMOBA_HOME/kumobad.sock` | The daemon: `unix:///path`, `http://127.0.0.1:port` (loopback or `localhost` only), or `https://host:port` for one on another machine |
| `KUMOBA_TOKEN` | contents of `KUMOBA_TOKEN_FILE` | Bearer token |
| `KUMOBA_TOKEN_FILE` | `$KUMOBA_HOME/token` | File holding the token |
| `KUMOBA_CA_FILE` | the public CAs | PEM CA certificates to trust for an `https://` daemon instead of the public ones |
| `KUMOBA_CERT_FILE`, `KUMOBA_KEY_FILE` | none | PEM client certificate and key, for a daemon that requires mutual TLS. These three apply only to an `https://` URL; with another URL the client stops with an error |
| `KUMOBA_PUBLIC_URL` | none | SDK only: base URL browsers reach the preview listener at, used for `expose()` and `liveView()` links instead of the daemon's own |
| `KUMOBA_USER` | the image's default user | SDK only: guest user for commands and files |

## Installer (`install.sh`) [#installer-installsh]

| Variable | Default | Meaning |
| --- | --- | --- |
| `KUMOBA_VERSION` | the latest release | Release to install, such as `0.18.0` |
| `KUMOBA_HOME` | `~/.kumoba` | Install directory |
| `KUMOBA_IMAGE` | `default` | `default`, `test` or `none` |