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

# VM workers

> Reference for Compose VM workers: which containers run in a VM, binary packages, the project tree, build.json, the sandbox adapter, error codes, and log lines.

A VM worker is a container whose `scripts.build` is `iii call sandbox::build worker=<container>`
and whose `scripts.run` is `iii call sandbox::start worker=<container>`. To set one up, see
[Using iii / Compose](https://iii.dev/docs/using-iii/compose.md#vm-workers). For how its builds and runs behave, see
[Understanding iii / Compose](https://iii.dev/docs/understanding-iii/compose.md#vm-workers).

## Which containers run in a VM

| Rule | Error |
| - | - |
| `scripts.run: iii call sandbox::start` only on a `bundle` package, a `binary` package, or a `path://` with `runtime.base_image` | `SANDBOX_RUN_NOT_A_VM_WORKER` |
| `scripts.run: iii call sandbox::start` on a `binary` package without `runtime.base_image` in its container | `SANDBOX_BINARY_WITHOUT_BASE_IMAGE` |
| `runtime.base_image` with a `scripts.run` other than `iii call sandbox::start`, or a `scripts.build` other than `iii call sandbox::build` (`""` included) | `BASE_IMAGE_WITHOUT_VM` |
| `runtime.base_image` that is not an image reference | `INVALID_BASE_IMAGE` |
| `scripts.build: iii call sandbox::build` only together with `scripts.run: iii call sandbox::start` | `SANDBOX_BUILD_WITHOUT_RUN` |
| `scripts.run: iii call sandbox::start` with a `scripts.build` other than `iii call sandbox::build` | `SANDBOX_RUN_WITHOUT_BUILD` |
| `worker=` on either line names the container's own key | `SANDBOX_WORKER_MISMATCH` |
| `iii call sandbox::start` on Windows | `SANDBOX_UNSUPPORTED_PLATFORM` (a bundle already fails at install with `BUNDLE_NEEDS_A_VM`) |
| `command=<cmd>` on a bundle or a binary | Refused by `sandbox::start` with `SANDBOX_INVALID_REQUEST` |

Compose checks every rule but the last when it loads the file. `iii compose build` checks them too,
with or without `--frozen`, before it downloads anything, so a CI job catches them without an
engine. It skips the Windows rule, but that does not let Windows build a project with VM
containers: the adapter package has no Windows build (see [Worker kinds](https://iii.dev/docs/using-iii/compose.md#worker-kinds)).

A line counts as one of these when its first three words are `iii call sandbox::start` or
`iii call sandbox::build`. Compose checks every rule when it loads the file, before any call.

A project needs the adapter when a container's `scripts.run` starts with `iii call sandbox::start`,
or when `engine.sandbox` names the project's own namespace. Compose then adds the generated adapter
container, marked `# added by compose::add`, when the file does not declare one. The start order on
the adapter is in `start_after`, in the file.

These rules apply after Compose rewrites a file from an older release: a missing `scripts.build`, a
missing adapter in `start_after`, a bundle without `scripts.run`, or a container with
`runtime.base_image` and no `scripts.run` is rewritten, not refused. See
[Upgrading / VM workers](https://iii.dev/docs/upgrading/explicit-vm-workers.md).

`compose::add`, and the rewrite, append the adapter's container key to `start_after`, after the keys
already there, which keep their order and comments. Adding `onboarding`, which already starts after
`state`, in a project whose adapter container is `sandbox-libkrun`, writes
`start_after: [state, sandbox-libkrun]`. An adapter in a container named `vm-adapter` is written as
`vm-adapter`: a container is named by its key, never by the package it runs.

A bundle runs on the host when its `scripts.run` is a host command. It runs `scripts.build` and
`scripts.run` in `.iii/workers/<container>/`, and gets `III_PACKAGE_DIR` and `III_PACKAGE_NAME`.
Binary packages keep their working directory. Both moves are edits of `scripts`, and later runs
leave them alone, with or without a lock.

## Binary packages

A `binary` package runs its host build as a child process. It runs in a VM when its container sets
`runtime.base_image`, the image the VM build starts from, since a binary package names none.

* **Build.** The container gets the Linux build of the host's architecture,
  `<arch>-unknown-linux-musl`, or `<arch>-unknown-linux-gnu` when the package publishes no musl
  build. A package with neither fails with `UNSUPPORTED_PLATFORM`. A static musl build runs on any
  base image; a glibc build needs a glibc image, such as Debian.
* **Lock.** Its `worker-compose.lock` entry has `vm: true`. The entry already lists every build the
  registry published, and each machine picks the Linux build of its own architecture, so one lock
  serves every machine. Moving the worker between the host and a VM resolves it again, and fails
  under `--frozen` with `COMPOSE_LOCK_OUT_OF_DATE`.
* **Run.** `.iii/workers/<container>/` holds the Linux build. The guest runs its executable, the
  first regular executable file in it, root first and in name order, with no arguments.
* **Host scripts.** On the host, a binary package may set `scripts` like any worker. `scripts.run`
  replaces the published executable, in the worker's usual working directory.
* **Not on the host.** Unlike the manifest's key, the container's `runtime.base_image` never keeps a
  worker on the host: with a `scripts.run` other than `iii call sandbox::start`, or a `scripts.build`
  other than `iii call sandbox::build` (`""` included), it fails with `BASE_IMAGE_WITHOUT_VM`.

## The project tree

```text theme={"theme":{"light":"catppuccin-latte","dark":"dark-plus"}}
my-project/
├── worker-compose.yaml
├── worker-compose.lock
├── .iii/                    # hidden from VMs by name
│   ├── project.ini          # the project's id, written by iii project init
│   ├── compose/             # Compose state and the project token; III_COMPOSE_STATE_DIR moves it
│   ├── workers/             # packages, one directory per container; like node_modules
│   │   ├── .gitignore       # "*", written by Compose
│   │   ├── .packages.json   # container -> { name, version, sha256 }
│   │   ├── .lock            # held while Compose copies packages
│   │   ├── onboarding/
│   │   ├── sandbox-libkrun/
│   │   └── state/
│   └── build/               # one directory per container that has a build
│       ├── .gitignore       # "*", written by Compose
│       ├── onboarding/
│       │   ├── image.erofs  # the image the run boots (VM containers)
│       │   ├── image.id     # its build_id, written by the adapter
│       │   └── build.json
│       ├── link/
│       └── api/
│           └── build.json   # host builds record build.json without an image
└── link/                    # a path:// worker, as today

~/.iii/cache/                # global: base images (docker.io/iiidev/node, .../python, ...)
~/.iii/compose/packages/     # global: extracted packages, unchanged; the source of .iii/workers/
~/.iii/sandbox/workers/      # adapter-owned: each VM's persistent data disk
```

* `.iii/workers/` and `.iii/build/` are always in the `.iii/` beside the compose file, also when
  `III_COMPOSE_STATE_DIR` moves Compose's state: the sandbox adapter reads only under the compose
  file's directory and the package cache. Nothing of Compose's lands at the project root, and a VM
  never sees either directory, `path://.` included.
* `.iii/workers/` is rebuilt from `worker-compose.lock`, and `.iii/build/` by a build. Both stay out
  of git like `node_modules`. Compose writes a `.gitignore` containing `*` in each, so a migrated
  project is covered without editing its own `.gitignore`, which keeps the rest of `.iii/`, such as
  `project.ini`.
* `.iii/workers/<container>/` is a copy of the extracted package from the global cache, which keeps
  its own layout. `.iii/workers/.packages.json` records which artifact each directory holds. It is
  stored outside the package directories, so no guest can write it.
* One copy runs at a time: the daemon and `iii compose build` both hold `.iii/workers/.lock` while
  they copy packages. A directory whose record matches the lock stays as it is, with what a host
  build wrote into it. Compose removes only what it made: the directories of containers no longer
  locked, the trees an earlier run replaced, and the temporary copies an interrupted run left.
* A directory is replaced through a copy made beside it. Its entry leaves `.packages.json` before
  the directory changes and comes back once the copy is in place, so an interrupted copy is made
  again by the next run.
* The replaced tree stays aside, as `.<container>.replaced-<id>`, until the next run removes it,
  whether its process still runs or not. A host bundle that runs through the swap keeps what it
  reads relative to its working directory. What it resolves through an absolute path
  (`III_PACKAGE_DIR`, Node's `require`, Python's `sys.path`) comes from the new tree until the
  container restarts.
* When Compose copies a container's package directory again because it was missing or its record
  could not be read, it deletes that container's host-build `build.json`, so the next start runs
  the first build again. A package update keeps the record and rebuilds. A VM build keeps its
  record: its image holds its own copy of the package.
* The image is one file, `image.erofs`, never a directory tree: a Linux tree on a case-insensitive
  filesystem (APFS) would be corrupted.

```json .iii/workers/.packages.json theme={"theme":{"light":"catppuccin-latte","dark":"dark-plus"}}
{ "schema": 1, "containers": { "onboarding": { "name": "onboarding", "version": "0.2.0", "sha256": "sha256:8c3406..." } } }
```

## `build.json`

```json .iii/build/onboarding/build.json theme={"theme":{"light":"catppuccin-latte","dark":"dark-plus"}}
{
  "schema": 1,
  "container": "onboarding",
  "source": { "kind": "package", "name": "onboarding", "version": "0.2.0", "sha256": "sha256:8c3406..." },
  "command": "iii call sandbox::build worker=onboarding",
  "dependency_files": { "package.json": "sha256:2f1c...", "package-lock.json": "sha256:9a07..." },
  "image": {
    "file": "image.erofs",
    "build_id": "sha256:7d41...",
    "base_image": { "declared": "docker.io/iiidev/node:latest", "reference": "docker.io/iiidev/node:latest", "digest": null },
    "adapter": { "name": "sandbox-libkrun", "version": "0.5.0" },
    "contract": { "major": 1, "minor": 4 }
  },
  "built_at": "2026-11-10T14:03:22Z"
}
```

A `path://` container records `"source": { "kind": "path", "dir": "./link" }`: the declared path,
relative to the compose file. A host build writes the same keys without `image`.

* Every hash is written `sha256:<hex>`. Times are RFC 3339 UTC.
* `dependency_files` holds the hash of each of these files that exists at the root of the worker
  directory: `package.json`, `package-lock.json`, `pnpm-lock.yaml`, `yarn.lock`, `bun.lockb`,
  `requirements.txt`, `pyproject.toml`, `uv.lock`, `poetry.lock`, `Cargo.toml`, `Cargo.lock`,
  `go.mod`, `go.sum`.
* `image.build_id` is what the adapter wrote in `image.id`. `adapter` and `contract` are what
  Compose's own `adapter::info` reports.
* `image.base_image.declared` is the container's `runtime.base_image`, else the manifest's, or
  `null` when the adapter chose the image. `reference` is the image the build asked for, the
  declared one, empty when there is none. `digest` is `null`: the image the adapter resolved is in
  the answer of `sandbox::build`, which Compose does not read. The out-of-date check compares
  `declared` only.
* Compose writes `build.json` once `scripts.build` exited 0, for a VM build as for a host build. For
  a VM build, the adapter has renamed the new image into place by then.
* Compose reads the container's `source` before the build and again before it writes `build.json`.
  If an `iii compose build` in another process replaced the package meanwhile, the build records
  nothing and fails with `BUILD_INPUT_CHANGED`. Build again to record the new package.
* Writes are atomic: a temporary file beside `build.json`, then a rename. Leftover temporary files
  are swept. A `build.json` whose `build_id` does not match the image fails the run with
  [S508](https://iii.dev/docs/creating-workers/sandboxes.md#S508). The fix is a rebuild.

## Error codes

| Code | When |
| - | - |
| `VM_SCRIPTS_MISSING` | `--frozen` on a file with containers to rewrite, or a start that reaches a container not rewritten yet. |
| `SANDBOX_ADAPTER_NOT_DECLARED` | `--frozen` on a project that needs the adapter and declares none. |
| `SANDBOX_ADAPTER_TOO_OLD` | The adapter is outside `^0.5` and Compose may not update it. |
| `SANDBOX_BUILD_UNSUPPORTED` | `sandbox::build` or `sandbox::start` with an adapter that does not advertise `worker.build`, or another feature a VM needs from contract 1.4. |
| `SANDBOX_BINARY_UNSUPPORTED` | `sandbox::build` or `sandbox::start` of a binary package, with an adapter that does not advertise `worker.binary`. |
| `SANDBOX_RUN_NOT_A_VM_WORKER` | `iii call sandbox::start` on a container that is not a bundle, a binary, or a `path://` with `runtime.base_image`. |
| `SANDBOX_BINARY_WITHOUT_BASE_IMAGE` | `iii call sandbox::start` on a binary package whose container sets no `runtime.base_image`. |
| `BASE_IMAGE_WITHOUT_VM` | `runtime.base_image` on a container whose `scripts.run` or `scripts.build` keeps it on the host. |
| `INVALID_BASE_IMAGE` | `runtime.base_image` that is not an image reference. |
| `SANDBOX_BUILD_WITHOUT_RUN` | `iii call sandbox::build` without `iii call sandbox::start`. |
| `SANDBOX_RUN_WITHOUT_BUILD` | `iii call sandbox::start` with another `scripts.build` command. |
| `SANDBOX_WORKER_MISMATCH` | `worker=` on a VM container's `scripts.build` or `scripts.run` that is not the container's own key. Refused when the file loads and by `iii compose build`. |
| `SANDBOX_UNSUPPORTED_PLATFORM` | A container whose `scripts.run` is `iii call sandbox::start`, on Windows. |
| `SANDBOX_INVALID_REQUEST` | `sandbox::build` or `sandbox::start` with a request that does not read, such as a hand-run `sandbox::start` without `build_id`, or `command=` on a package. |
| `SANDBOX_CONTRACT_UNSUPPORTED` | The adapter implements another major version of the sandbox contract. |
| `WORKER_EXITED` | The VM that `sandbox::start` follows exited with another code than `0`, or on a signal. `iii call` exits with `1`, and the container's `restart` policy applies. |
| `BUILD_FAILED` | A first build or a package rebuild failed. Carries `{ code, message }`. |
| `BUILD_INPUT_CHANGED` | A build whose source was replaced while it built. Nothing is recorded. Build again. |
| `TIMED_OUT` | A build that ran past `scripts.build_timeout`. The previous image stays. |
| `OPERATION_CANCELLED` | A cancelled `compose::build`, add, or update, or a VM build whose caller left: Compose stopped it, or `Ctrl+C` on a hand-run `iii call sandbox::build`. |
| `INVALID_CONTAINER_KEY` | A container key that cannot name `.iii/build/<key>/` and `.iii/workers/<key>/`. |

The sandbox adapter adds the S-codes [S507](https://iii.dev/docs/creating-workers/sandboxes.md#S507),
[S508](https://iii.dev/docs/creating-workers/sandboxes.md#S508), and [S509](https://iii.dev/docs/creating-workers/sandboxes.md#S509).

## Log lines

| Line | When |
| - | - |
| `<c>: no build yet; running scripts.build` | A first build starts. |
| `<c>: package changed (<old> -> <new>); rebuilding` | A package update rebuilds the container. |
| `<c>: its build is a host build, and scripts.build now builds a VM image; rebuilding` | A host build is rebuilt as a VM image. |
| `<c>: its build is a VM image, and scripts.build now runs on the host; rebuilding` | A VM image is rebuilt on the host. |
| ``<c>: dependencies changed since the last build (<files>); run `iii call compose::build worker=<c>` `` | A dependency file changed since the last build. |
| ``<c>: base image changed since the last build (<old> -> <new>); run `iii call compose::build worker=<c>` `` | `runtime.base_image` changed since the last build. A side without one reads `the adapter's default`. |
| `<c>: migrated to the explicit VM mode (scripts.build/scripts.run: iii call sandbox::...)` | Compose rewrote a VM container of a file from an older release. |
| `<c>: scripts.run now runs inside the VM (iii call sandbox::start command=...); to keep it on the host, set scripts.build ("" when there is nothing to build)` | Warning: the rewrite wrapped a `scripts.run` command. |
| `migration due: <c>, <c>; the next up rewrites them` | Warning from `compose::validate`. |
| `<c>: kept the pre-build data disk at <path>` | The adapter kept the data disk of a VM from an older release. In the container's logs and the adapter's log. |
| `sandbox::start: reattached to VM <vm_id> instance <n>` | `sandbox::start` found the VM of the same state running, and follows it. |
| `<c>: removed the VM state of <key>; kept its data in <paths>; a container added again as <c> boots with it` | `compose::remove` without `prune`. |
| `<package>: the guest runs <executable> from <dir>` | The executable chosen for a binary package, in its build output. |
| `<c>: removed the VM state and data of <key>` | `compose::remove prune=true`. |
| `<c>: kept VM <vm_id>: <adapter> <version> cannot keep its data (no worker.prune); its state stays in ~/.iii/sandbox/workers/<vm_id>, and a container added again as <c> boots with it` | `compose::remove` without `prune`, with an adapter lacking `worker.prune`. Nothing is deleted. |

## Sandbox adapter

`sandbox-libkrun` 0.5.0 is the first release with sandbox contract 1.4: `worker.build`,
`worker.binary`, and `worker.prune`. Compose needs that contract for VM workers, and
`compose::update` moves the adapter container only within `^0.5`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.