@selfbuilding/sandbox-docker
v0.1.0
Published
Docker sandbox provider.
Readme
@selfbuilding/sandbox-docker
The Docker sandbox provider: local development, CI and the reference adapter for the provider contract.
import { docker } from "@selfbuilding/sandbox-docker";
const provider = docker({ build: true }); // builds selfbuilding/<harness>:<version> locally with your UID| Option | Default | Meaning |
|---|---|---|
| image | the spec's image | Use this image for every box that is not restored from a snapshot |
| build | false | Build a missing official image locally (agent UID/GID = this machine's user) instead of pulling it |
| mount / worktree | "isolated" | "worktree" bind-mounts worktree at /selfbuilding/work; .git/config, hooks and info are read-only. Snapshot and fork are refused in this mode |
| socketPath | the local daemon | Docker socket |
| deadlineMs | 120 s | One deadline for openOrCreate/open, retries included |
| probeBudgetMs | 20 s | First-pass budget per ref when converging ghost refs |
| limits | 7-day session cap, expireKeeps: "filesystem" | Provider limits |
How the contract maps onto Docker:
- A box is a container running
sleep infinityunderdocker-init, named<sandbox name>.<deployment>so the daemon's unique-name rule makesopenOrCreateatomic per key./run/selfbuildingand/tmpare anonymous volumes, so secrets never land in a snapshot image. find/listuse label filters only and never wake anything. The key's scope and other adapter-private values live insandbox-docker.*labels and surface asref.meta, never asref.labels.pauseis the cgroup freezer (memory kept).openunpauses, or starts a stopped box (filesystem only), then probes the guest until it answers.execruns withTty: falseand demultiplexed streams; the deadline is enforced inside the box by GNUtimeout.spawnuses the detachedsetsid nohupshim;attachreads the log by byte offset.- Files move as tar streams through the archive API; owner and mode are set explicitly afterwards.
- Docker has no TTL and container labels are immutable, so
extendLifetimewrites the lease to/selfbuilding/state/expires-at;find/listreport it asselfbuilding.expiresAtfor the reaper. snapshotisdocker commit(filesystem).forkcommits the parent once and boots each child from that image.
Tests: pnpm vitest run packages/sandbox-docker runs offline against an in-memory daemon. The conformance and
placement suites run only with SELFBUILDING_E2E_DOCKER=1 and a reachable daemon (SELFBUILDING_DOCKER_SOCKET to
point elsewhere); SELFBUILDING_E2E_DOCKER_IMAGES=1 also checks the Claude Code image.
