koi
Documentation / architecture

Sandbox mode

In sandbox mode the host yokai starts a Linux VM and runs a second yokai inside it. The agent and the sensors run in the VM, and your repository is mounted at the same path.

Why a sandbox

Unattended runs default to approve-all: the agent may run any command. A sandbox limits what that can reach and gives every run the same tools, defined in a file your repository owns. The next person who clones the repository can build the same environment.

Sandbox mode is optional. Without it, Yokai runs on your machine with whatever is installed there.

How it fits together

Two yokai processes take part. The one you start on the host is the launcher. The one inside the VM is the real supervisor.

The supervisor moves into the VM
Host launcher, Linux VM and the shared repository The yokai process on the host reads settings from the repository and starts the inner yokai inside a Linux VM run by sbx or container. Inside the VM, the inner yokai talks to the coding agent over ACP and runs the sensors. The agent edits files and the sensors read the tree in the repository, which is mounted into the VM at the same path as on the host. yokai on host exec Linux VM · sbx or container Inner yokai Coding agent Sensors reads settings edits Repository, mounted at the same path

When sandbox.enabled is true and you did not pass --host, the launcher:

  1. Creates the named sandbox from your image if it does not exist. The name defaults to yokai-<repository folder>.
  2. Copies a Linux build of yokai into the VM: /home/agent/.local/bin/yokai with Docker Sandboxes, /usr/local/bin/yokai with Apple Container.
  3. Runs .koi/sandbox-setup.sh once, if it exists, and records that it ran.
  4. Starts the inner yokai with YOKAI_SANDBOX_INNER=1, forwarding your launch flags. That variable stops the inner process from starting another sandbox or opening setup.

The repository is mounted read-write at the same absolute path as on the host. Changes the agent makes inside the VM land in your checkout directly. The VM can reach the network.

Backends

Backend Setting Host tool Notes
Docker Sandboxes backend: docker (default) sbx, with Docker Desktop running Credentials can come from the host through sbx secret
Apple Container backend: apple container, macOS 26 on Apple silicon Defaults to 8 GB of memory and 4 CPUs; you sign the agent in inside the VM

The image

The image is built from .koi/Dockerfile.sandbox, a file in your repository. It must install the coding agent you configured and every tool your sensors call. Yokai does not install agents for you. Setup can propose a Dockerfile; Approve and build saves it, builds the image and replaces the named sandbox.

# .koi/yokai.yml
sandbox:
  enabled: true
  backend: docker
  image: daylist-sandbox

.koi/sandbox-setup.sh is an escape hatch for setup the image cannot do. Prefer the Dockerfile.

Linux binaries

The VM needs a Linux yokai of the same version as the host binary. The launcher finds one in this order:

  1. The path in YOKAI_LINUX_BINARY, if set.
  2. A cached copy for this version at ${KOI_DATA_DIR:-~/.local/share/koi}/bin/yokai-linux-<arch>-v<version>.
  3. A download of yokai-<arch>-unknown-linux-musl.tar.xz from the GitHub release v<version>, checked against its .sha256 and then cached.
  4. An older local build at ${KOI_DATA_DIR:-~/.local/share/koi}/bin/yokai-linux-<arch>, only if the download fails.

<arch> is the host's architecture, aarch64 or x86_64, because the VM runs the host's. Pinning the version keeps the supervisor inside the VM identical to the one on the host. yokai doctor reports which copy the next launch will use. Sandboxes covers the dev-build case.

Gate review and the environment

Sensors are reviewed in the environment they will run in. The review fingerprint in .koi/yokai.yml covers the backend, the image, the Dockerfile and the setup hook. Switching from host to sandbox, or rebuilding the image, needs a new smoke run of the same scripts before Yokai runs a phase.

What can go wrong

  • opencode not found inside the VM. The image does not install the agent. Add it to the Dockerfile, rebuild and recreate the sandbox.
  • The image changed but the tools did not. An existing sandbox keeps its old filesystem. Recreate it through setup, or remove it with sbx rm (Docker) or container stop and container rm (Apple).
  • no release asset at … or could not download …. The launcher could not fetch the Linux yokai. Check the network, or set YOKAI_LINUX_BINARY to a Linux build.
  • The host login works and the VM login fails. With Apple Container, sign in inside the VM, for example container exec -it yokai-daylist opencode and then /connect.

To run one launch on the host anyway, use yokai --host. Sandboxes is the step-by-step guide.