Sandboxes
Every command a session runs (the repository’s code, the code a model wrote, the checks of a skill) runs in a sandbox, never in the kōjō process. This page is for the person who deploys kōjō: it covers what every driver must do, the kinds of drivers and how to choose one, the settings they share, and what a sandbox image must contain. Each driver, and the egress proxy kojo-proxy, has a page of its own, listed at the end of this page.
The driver contract
A driver is the adapter between kōjō and one sandbox backend. The contract is in internal/sandbox/sandbox.go. The core only ever talks to a sandbox through it.
Every driver must do this:
| Call | What the driver must do |
|---|---|
Name |
Return its key in kojo.yaml. |
Create |
Start a sandbox from a spec (image, resources, workspace, egress policy, TTL) and wait until a command runs in it. Refuse a spec that asks for a Docker daemon it cannot provide, with ErrUnavailable. |
Get |
Find a sandbox created earlier, also by another process or after a restart. Return ErrNotFound when it is gone. |
Destroy |
Remove the sandbox and its workspace. |
Health |
Report the isolation level, the backend version, whether sandboxes can run their own Docker daemon, and whether egress is enforced. |
Every sandbox must do this:
| Call | What the sandbox must do |
|---|---|
Exec |
Run a command and wait for it. Stream output, and capture stdout and stderr up to a cap. A non-zero exit code is a result, not an error. A command that times out is killed with every process it started and reported with exit code 124. |
CopyIn |
Extract a tar stream into a directory. |
CopyOut |
Return a file or directory as a tar stream. |
ApplyPolicy |
Replace the sandbox’s egress allowlist and credentials. The core calls it before every skill runs, which narrows the sandbox to that skill’s allowlist and refreshes short-lived tokens. |
Two rules hold for every driver that isolates:
- A sandbox sees placeholder tokens only. Real credentials are set on requests outside the sandbox, by a proxy, and only for allowlisted hosts.
- Egress is deny by default. A sandbox reaches the hosts on its allowlist and nothing else.
Health reports one of four isolation levels:
| Isolation | Meaning | Accepted outside dev mode |
|---|---|---|
microvm |
A dedicated kernel per sandbox (sbx, Kata, e2b) | yes |
gvisor |
A user-space kernel (runsc) |
yes |
container |
A plain container on the host’s kernel | no |
none |
No isolation (the fake driver) | no |
A session has one sandbox per image. The repository is cloned into /workspace. When two skills of a session name different images, the session creates a second sandbox and copies the workspace into it. The session’s sandboxes are destroyed when it ends.
Drivers
A driver is one of four kinds, by where its sandboxes run: on one machine, the host that runs kōjō (sbx); on Kubernetes, as pods of your cluster (k8s); at a sandbox service, outside your infrastructure or cluster (e2b); and for development, as plain containers or in memory (docker and fake, which need dev: true). Pick the kind that matches what you run; each production kind has one driver.
| Kind | Driver | Isolation | Where sandboxes run | Egress enforced by | Own Docker daemon |
|---|---|---|---|---|---|
| On one machine | sbx |
microvm |
Docker Sandboxes on the host that runs kōjō | sbx’s own host proxy | yes |
| On Kubernetes | k8s |
microvm (Kata) or gvisor |
Pods in a cluster, through Kubernetes Agent Sandbox | kojo-proxy plus a NetworkPolicy | with Kata only |
| At a sandbox service | e2b |
microvm |
At an E2B-compatible service: E2B Cloud, a self-hosted E2B or CubeSandbox | kojo-proxy plus the service’s firewall, set per sandbox | no |
| For development | docker |
container |
Plain containers on a Docker daemon. Development only; needs dev: true |
kojo-proxy plus an internal Docker network | no |
| For development | fake |
none |
In memory; nothing runs. For tests; needs dev: true |
nothing | no |
Choosing a driver
- On one machine. One machine with hardware virtualization: use
sbx. kōjō must run on that same machine, as a host process. Its requirements and settings: sbx driver. - On Kubernetes. A Kubernetes cluster: use
k8s. Use a Kata RuntimeClass when the nodes can start VMs, and gVisor when they cannot. Skills that need their own Docker daemon get one only with Kata. Its requirements and settings: k8s driver. - At a sandbox service. An E2B account, or a self-hosted E2B or CubeSandbox you already run: use
e2b. kōjō then needs no virtualization and no cluster of its own, only a kojo-proxy the service’s sandboxes can connect to. The service bills a sandbox while it runs. Its requirements and settings: e2b driver. - For development. A laptop, to work on kōjō itself or try it with code you trust: use
dockerwithdev: true. See Development drivers and Development.
Do not point docker or fake at code you do not trust. kōjō refuses to start with either unless dev: true is set, and kojo doctor fails its mode and isolation checks while it is.
Configuring a driver
The driver is boot configuration: it is set in kojo.yaml and changing it needs a restart. The keys below are the ones every driver reads; each driver’s own keys are on its page. The full list, with every key’s type, is in the kojo.yaml reference, and the schema is kojo.schema.json.
Check a file without starting anything with kojo config validate -f kojo.yaml.
Settings shared by all drivers
| Key | Default | Meaning |
|---|---|---|
dev |
false |
Development mode. Allows the docker and fake drivers and a plain-container RuntimeClass on Kubernetes. |
sandbox.driver |
none, required | sbx, k8s or e2b; docker or fake with dev: true. |
sandbox.image |
ghcr.io/xavidop/kojo-toolchain:<version>; sandbox.e2b.template on e2b |
Image of a sandbox whose skill names none in its kit. On e2b it is a template. See Sandbox images. |
sandbox.ttl |
4h |
How long a sandbox may live. A duration such as 90m or 4h. |
sandbox.max_resources |
none | The most CPU, memory and disk any kit gets: {cpu: "2", memory: 4Gi, disk: 20Gi}. See Resources, timeouts and lifetime. |
sandbox.proxy.* |
see kojo-proxy | kojo-proxy settings. Not used by sbx and fake. |
Docker inside a sandbox
A skill’s kit can set needs_docker: true to ask for a Docker daemon of its own inside the sandbox (to build images or start services for its tests). Five built-in skills do: reproduce-bug, fix-bug, write-tests, build-feature and flaky-test-hunt.
Whether the request is honoured depends on the driver:
| Driver | needs_docker |
|---|---|
sbx |
Honoured. The engine runs inside the microVM. |
k8s with Kata |
Accepted: the sandbox container runs privileged inside the pod’s own VM. See the note below. |
k8s with gVisor |
Not available. gVisor cannot run a Docker daemon. |
k8s with a plain-container RuntimeClass |
Not available. |
e2b |
Not available. |
docker |
Not available. The driver never starts a privileged container. |
fake |
Not available. |
On k8s with Kata the driver grants the privilege and does nothing else. It replaces the image’s command with a sleep loop and starts no Docker daemon, so the image must contain the Docker engine and a command in the sandbox must start it.
Where it is not available, the skill is not dropped. kōjō asks the driver once whether sandboxes can run Docker. When they cannot, it creates the sandbox without Docker, and the subagent’s instructions say that Docker is not available and that it must do what the task needs without building images or starting containers.
kojo doctor warns when the driver cannot provide Docker.
Sandbox images
A skill’s kit names its image. When it names none, the sandbox uses sandbox.image, and when that is empty, ghcr.io/xavidop/kojo-toolchain with the tag of the kōjō version (latest for development builds).
The default image is built from deploy/toolchain/Dockerfile. It is a Debian with bash, git, curl, wget, jq, ripgrep, make, a C toolchain, Python 3 with pip and venv, Go and Node.js, the Docker client with its buildx and compose plugins, a non-root user agent with uid 1000, and a /workspace that user owns. It meets the requirements of every driver below. It contains no Docker engine: a skill with needs_docker gets the daemon from the driver, and where the driver gives none the subagent is told to work without Docker. The release workflow builds it for linux/amd64 and linux/arm64. To build and smoke-test it locally as ghcr.io/xavidop/kojo-toolchain:dev:
make toolchain
A repository with other needs names its own image in its kit.
The other Dockerfiles in the repository are not sandbox images: Dockerfile builds the kojo image (distroless, no shell), and test/kind/node/Dockerfile builds the kind node with gVisor.
What an image must contain:
| Needed by | Requirement |
|---|---|
| The core, on every driver | sh, git, find, printf, tar |
sbx |
sbx’s base image contract: /bin/sh, /bin/bash, tar, git, CA certificates, and a non-root user agent with uid 1000 |
k8s |
sh, env, tar, tr, grep, kill, sleep. The image’s own command is replaced by a sleep loop. |
e2b |
A template instead of an image: see Templates. /bin/sh, id, mkdir, chown, cat, mv, rm, tar, tr, grep, kill and CA certificates. Commands run as the template’s default user. |
docker |
sh, sleep, true, id, chown, tar, tr, grep, sed, cut, kill (BusyBox or coreutils). Commands run as the image’s user. |
The egress probe of kojo doctor |
curl or wget. Without either, the probe reports a warning instead of a verdict. |
needs_docker |
A docker CLI in the image. On k8s with Kata also the Docker engine, which the driver does not start. |
| The skill | Whatever its checks and setup commands call: the language toolchain, test runners, linters |
The development compose stack uses alpine/git, which is enough for a repository that needs sh and git only.
Resources, timeouts and lifetime
A kit’s resources use Kubernetes quantity syntax ("4", 500m, 8Gi).
| Resource | sbx | k8s | e2b | docker |
|---|---|---|---|---|
cpu |
Whole cores, rounded up | Request and limit | The template’s | --cpus |
memory |
Mebibytes, at least 512 | Request and limit | The template’s | --memory, no swap on top |
disk |
Ignored | Size of the workspace volume. 10Gi when the kit names none, or max_resources.disk when that is less. |
The template’s | Not enforced |
The built-in kits ask for up to 8 CPUs and 16Gi of memory. To fit them to smaller machines, set sandbox.max_resources in kojo.yaml:
sandbox:
max_resources:
cpu: "2"
memory: 4Gi
disk: 20Gi
A kit that asks for more than a quantity of max_resources gets that quantity instead, and the driver logs what it lowered. A kit that asks for less, or names no quantity, is unchanged: the cap never adds a request. A quantity max_resources leaves out is not capped. It applies to every kit, built-in or not, on sbx, k8s and docker; on e2b the template decides and a kit’s resources are not sent. kōjō refuses to start when a quantity is not one.
Besides max_resources, the docker driver lowers a request to the CPUs and memory the Docker daemon has, because Docker refuses a container with more CPUs than it has. On k8s a pod that no node has room for fails the sandbox after sandbox.k8s.unschedulable_timeout; see Scheduling.
Timeouts and caps:
| What | Value |
|---|---|
| A command with no timeout of its own | 10 minutes |
The run_command tool |
timeout_seconds, default 600, at most 3600 |
| A goal check | The check’s timeout, default 10 minutes |
A kit setup command, the clone |
10 minutes each |
| Captured output of a command | 64 KiB each for stdout and stderr by default. Output beyond the cap is dropped from the middle. |
| Sandbox creation | 15 minutes on sbx; 5 minutes on k8s and docker, image pull included; 3 minutes on e2b |
A sandbox pod no node has room for (k8s) |
sandbox.k8s.unschedulable_timeout, default 2 minutes, within the 5 minutes of its creation |
| Sandbox lifetime | sandbox.ttl, default 4 hours |
A command that times out is killed inside the sandbox, with every process it started, and reported with exit code 124.
A kit’s setup commands run once per skill in a sandbox, before the skill’s first attempt, and each one is recorded as a step of the session.
A session that asks “Open a pull request?” keeps its change in its sandbox while it waits, so the question closes no later than 30 minutes before the sandbox’s sandbox.ttl runs out; without an answer the change is then published as a draft. A session that asks to merge destroys its sandboxes before it waits. See No answer.
A session destroys its sandboxes when it ends. The TTL is the safety net for a session that died without cleaning up: every 5 minutes kōjō removes the sandboxes whose TTL has passed. On Kubernetes the claim also has a shutdown time 10 minutes after the TTL, so the Agent Sandbox controller deletes it when kōjō is down. On e2b the TTL is the service’s own timeout, so the service removes the sandbox by itself. The sbx driver also removes generated kits that no sandbox uses, once they are 24 hours old.
Checking a deployment
kojo doctor reports on the sandbox setup:
| Check | Fails or warns when |
|---|---|
sandbox driver |
The backend is not usable (no sbx binary, no virtualization, no cluster access, missing CRDs, an E2B-compatible service that cannot be reached or refuses the API key) |
sandbox isolation |
The isolation level is container or none |
sandbox egress |
The driver reports that sandboxes can bypass the proxy |
sandbox docker |
Warning: sandboxes cannot run their own Docker daemon |
egress probe |
A test sandbox with an empty allowlist reached example.com, through the proxy or around it |
The probe creates a real sandbox from the default image. Skip it with kojo doctor --skip-probe.
Conformance suite
Every driver must pass one shared test suite, test/conformance. It makes “a sandbox sees placeholders only and has no way out except the allowlisted proxy” a tested property of each driver.
It covers: create, exec, copy and destroy; exit codes; environment; stdin; streaming; a timeout that kills the command; the output cap; workspace persistence across a new driver instance; ErrNotFound; a refused needs_docker; egress allow and deny, through the proxy and directly; placeholder to injected credential; no secret visible inside the sandbox; TTL cleanup.
make conformance
make conformance DRIVER=docker
make conformance DRIVER=k8s
make conformance DRIVER=sbx
make conformance DRIVER=e2b
DRIVER |
Needs |
|---|---|
fake (default) |
Nothing. It also runs the e2b driver against an E2B-compatible service inside the test process, which runs a sandbox’s commands on the test machine. |
docker |
A Docker daemon |
k8s |
The kind cluster of make dev-kind, described in test/kind/README.md. KOJO_K8S_RUNTIME_CLASS=runc runs it on plain containers instead of gVisor. |
sbx |
The sbx CLI, signed in, on a host with hardware virtualization |
e2b |
An E2B-compatible service: E2B_API_KEY, and E2B_DOMAIN, E2B_API_URL or E2B_SANDBOX_URL for one that is not E2B Cloud. KOJO_E2B_TEMPLATE names the template (default base); it needs curl for the egress cases. KOJO_E2B_PROXY_HOST is the address under which the service’s sandboxes reach the machine running the tests; without it the egress and credential cases are skipped. |
A case a setup cannot run is skipped with a reason that names the missing capability, and the script fails when a driver’s whole test was skipped, so a skip never counts as a pass. On the sbx driver the egress and credential cases are skipped even on a real sbx install: the suite’s throwaway upstream is not reachable through sbx’s host proxy. Kata is not covered on kind, because kind nodes are containers and cannot start VMs.
The local stacks and the other test layers are on the Development page.
Driver pages
| Kind | Page | What it covers |
|---|---|---|
| On one machine | sbx driver | Docker Sandboxes on the host that runs kōjō: requirements, the deny-all preset, the kits kōjō generates, limits |
| On Kubernetes | k8s driver | Agent Sandbox pods isolated by Kata or gVisor: requirements, templates and claims, isolation levels, limits |
| At a sandbox service | e2b driver | E2B Cloud, a self-hosted E2B or CubeSandbox: where kojo-proxy must be, templates, limits |
| For development | Development drivers | docker, plain containers, and fake, in memory; both need dev: true |
kojo-proxy is the egress proxy of the k8s, e2b and docker drivers: how a sandbox reaches the network, embedded and remote mode, egress allowlists, credential injection, private addresses, its metrics, and how to run it apart from the server.