Development drivers

The drivers for development: docker runs sandboxes as plain containers, and fake keeps them in memory for tests. This page is for whoever works on kōjō or tries it with code they trust; the local stacks that use these drivers are on Local stacks.

docker

The docker driver runs each sandbox as a plain Docker container. It is for development only: a container shares the host’s kernel. It needs dev: true, and kojo doctor fails its isolation check.

It keeps the rest of the security model, so a development setup behaves like a real one: credentials go to kojo-proxy and never into the container, and sandboxes join a Docker network created with --internal and -o com.docker.network.bridge.inhibit_ipv4=true: it has no route out, and the host has no address on it.

Configuration

dev: true
sandbox:
  driver: docker
  image: alpine/git:v2.54.1
  docker:
    binary: docker
Key Default Meaning
sandbox.docker.binary docker on PATH The docker CLI.
sandbox.docker.network empty Docker network sandboxes join. When empty, kōjō creates the internal network kojo-sandbox. A network named here must exist. When it is not internal, or the host has an address on it, egress is not enforced and Health says so.

How it works

Docker gives an internal network’s bridge an address of the host, its gateway, unless the network is created with -o com.docker.network.bridge.inhibit_ipv4=true. At that address a container reaches every service of the host that listens on all interfaces, without the proxy: on Linux the machine itself, with Docker Desktop its VM. So the network kōjō creates has no gateway, and on a network named in sandbox.docker.network that has one, Health and kojo doctor report egress as not enforced and say how to recreate it. A kojo-sandbox network created by an earlier version has a gateway: remove it with docker network rm kojo-sandbox while no sandbox runs, and kōjō creates it again.

How sandboxes reach the proxy depends on where it runs:

  • The proxy is attached to the sandbox network (docker compose): sandboxes use its service name. In remote mode its admin API must not listen on that network, since whoever has the admin token can change any sandbox’s allowlist: set sandbox.proxy.admin_listen to a name only the server’s network has. The development stack gives the proxy the alias kojo-proxy-admin on its default network and sets admin_listen: "kojo-proxy-admin:3129", so the admin API listens on that address only.
  • The proxy is on the host (kojo serve on a laptop): the driver starts a relay container (alpine/socat) attached to the sandbox network and the default bridge. It forwards one TCP port to the proxy and nothing else. It carries at most 1024 connections at once, one process each, and waits for one to end before it accepts another; the container is limited to 1040 processes and 256 MiB.

Containers run with no-new-privileges, without the NET_RAW capability, and with a limit of 4096 processes.

A kit’s resources.cpu and resources.memory become --cpus and --memory, in two steps. First sandbox.max_resources, when set, lowers what the kit asks for (see Resources). Then the driver lowers the result to what the Docker daemon has, which it reads once with docker info (NCPU and MemTotal) the first time a kit asks for CPU or memory. Docker refuses a container with more CPUs than the daemon has, so without this a kit that asks for 8 CPUs could not start on a 4-CPU machine. Each lowered value is logged with its reason. A kit that asks for less is unchanged, and one that names no CPU or memory gets no limit.

Limits

Sandboxes on the same network can connect to each other; resources.disk is not enforced; a sandbox with its own Docker daemon is refused, because that takes a privileged container; and the driver runs a few fixed shell snippets as root in the container (installing the CA bundle, killing a timed-out command).

fake

The fake driver keeps sandboxes in memory. Files copied in can be copied out, and no command runs. It records what the core asked for, so unit tests can assert it. The allowlist and credentials of a policy are recorded and not enforced. It needs dev: true and has no settings:

dev: true
sandbox:
  driver: fake
Scroll to move. + - zoom, 0 fit, Esc close.100%