Run pi coding agents inside Docker Sandboxes (sbx): a bit more isolation, a bit less YOLO.
The main kit is the factory 🏭: a sandbox where several pi agents work on your project's tickets in parallel, organized in Herdr panes, with an optional web dashboard. There are also single-pi kits if you only want one agent.
- Set up the factory
- Everyday use
- Keep the code in the sandbox
- Reference
- Other kits
- Developing these kits
You need Docker Desktop and sbx 0.47 or newer (install sbx). Run every command in this section on your computer (the host), unless a step says "in the sandbox".
sbx only installs kits from sources on its allowlist, and by default that is Docker Hub alone. Allow the factory (ghcr.io/geut/) and the dashboard (ghcr.io/dpaez/):
sbx settings set kit.allowedSources '["docker.io/","ghcr.io/geut/","ghcr.io/dpaez/"]'This replaces the whole list. If sbx settings get kit.allowedSources already shows other sources, keep them in the new list.
sbx run --name factory ghcr.io/geut/sbx-shell-pi:node-24-factory /path/to/your/project \
--kit ghcr.io/dpaez/sbx-kit-factory-dashboard:0.3.0The --kit line adds the dashboard. Leave it out if you don't want it. For a Python project, also add --kit ghcr.io/geut/sbx-shell-pi:python (see python/). The kit set is fixed when the sandbox is created, so adding a kit later means creating a new sandbox. So is the size of the Docker daemon's volume, 10 GiB by default: for tests that run databases or other services in Docker, prefix the command with DOCKER_SANDBOXES_DOCKER_SIZE=40g.
This mounts your project from the host, so the sandbox and your computer share one checkout, .venv and .env included. To keep them apart, keep the code in the sandbox instead.
When the sandbox starts, you land in Herdr, a terminal multiplexer where the agents run side by side.
The agents need an API key for your model provider. In a second terminal on the host:
sbx secret set-custom --sandbox factory --host [provider.endpoint] --env [API_KEY_NAME] --value [SECRET]Many providers have a built-in shortcut instead; see sbx secret. The key never enters the sandbox: the sandbox proxy adds it to outgoing requests.
In the Herdr pane, from your project's root:
cd "$WORKSPACE_DIR" # your project, if you're not already there
factory-upThe first time, this creates .factory/FACTORY.json with starter settings, then starts the factory server in a Herdr workspace named factory. Open .factory/FACTORY.json and check the models (models.work and models.review) before going on. The factory-skills README explains every setting.
Then start pi in a pane and run the command below. The server installs pi's /factory extension each time it starts, so a pi that was already open needs /reload first.
/factory start
Each ticket gets its own Herdr tab, with agents for planning, work, review and wrap-up.
On the host:
sbx ports factoryOpen the host port listed for factory-dashboard in your browser. Until factory-up has run, the dashboard shows a page asking you to run it.
- Detach from Herdr with
ctrl+b, thenq. The agents keep running (Herdr quick start). - Reattach with
sbx run factory.sbx lslists your sandboxes. - After a restart (
sbx stop, thensbx run factory), the factory server starts again by itself once Herdr is up. There's no need to runfactory-upagain. - Update the factory with
/factory updatewhen pi says a new release is out (Updating the factory). - Edit files with
fresh, the default editor. Review diffs withhunk diff.
By default the sandbox mounts your checkout from the host at the same path, and the factory's worktrees live inside it, under .factory/worktrees/. Both sides then work on the same files: a uv sync or npm install on one side replaces the other's .venv or node_modules with one for its own OS, config loaders inside the sandbox can read your .env, and both share one .git. The python kit refuses the worst of it, but only a separate checkout prevents it.
A sandbox made with sbx create and no path mounts nothing from your computer (sbx run always mounts one: the current directory when you don't pass a path). You clone the repository into it, and everything the factory makes (worktrees, environments, caches, its database) stays on the sandbox's own disk:
| Host mount (default) | Code in the sandbox | |
|---|---|---|
| Checkout | your directory, at the same path | a clone in ~/workspace |
.venv, node_modules, .env, .git |
shared with your computer | the sandbox's own |
| You see the agents' work | immediately, in your checkout | when you fetch it (below) |
sbx rm |
leaves your files | deletes the clone and anything not pushed or copied out |
sbx run --clone sits in between: the sandbox gets its own clone and can't change your repository, but your whole directory is readable at /run/sandbox/source, untracked .env files included. Use the sandbox's own clone if that matters.
-
Create the sandbox with
sbx createand no path, with the same kits, then attach to it:sbx create --name factory ghcr.io/geut/sbx-shell-pi:node-24-factory \ --kit ghcr.io/dpaez/sbx-kit-factory-dashboard:0.3.0 sbx run --name factory
The sandbox's Docker daemon keeps images, containers and volumes on a volume of its own, 10 GiB by default, and the factory's worktrees and caches are on the sandbox's disk too. A test suite that runs databases or other services in Docker can fill it. For heavier workloads, choose the size when you create the sandbox, since it can't grow later:
DOCKER_SANDBOXES_DOCKER_SIZE=40g sbx create --name factory …
sbx settings set sandbox.disk.dockerVolume 40gchanges the default for every new sandbox. -
For a private repository, or for the factory to push, give the sandbox a GitHub token (on the host):
sbx secret set github --sandbox factory -t "$(gh auth token)". The proxy adds it to HTTPS requests to GitHub; nothing from your SSH agent or git config is used. -
In the sandbox, clone into the workspace directory itself (the dashboard and the restart hook look there), over HTTPS:
git clone https://github.com/OWNER/REPO.git ~/workspace -
.factory/isn't in the repository. To reuse your settings, copy them in from the host; otherwisefactory-upwrites a starterFACTORY.json. BringFACTORY.json,CONTEXT.md, and every file they reference, such as setup or validation scripts in.factory/bin. From your checkout on the host, with the list adjusted to your factory:tar -czf /tmp/factory-config.tgz -C .factory FACTORY.json CONTEXT.md bin sbx cp /tmp/factory-config.tgz factory:/tmp/factory-config.tgz sbx exec factory sh -c 'mkdir -p ~/workspace/.factory && tar -xzf /tmp/factory-config.tgz -C ~/workspace/.factory'
tarkeeps the scripts executable. Leave out the rest of.factory/(worktrees, the factory's database,local.token,dashboard.env), along with.envand.venv: the sandbox makes its own. -
Continue with step 3.
factory-upruns in~/workspace.
Tickets come from the tracker as before. To open a shell in the sandbox from the host, run sbx exec -it factory bash.
-
Committed work: with
codeHost.pullRequestson, wrap-up pushes the ticket's branch and opens the pull request. Otherwise push it from the sandbox (git push origin <branch>), or carry it in a bundle:# in the sandbox git -C ~/workspace bundle create /tmp/work.bundle <branch> # on the host, in your checkout sbx cp factory:/tmp/work.bundle . && git fetch ./work.bundle <branch>:<branch>
-
Uncommitted changes in a worktree:
git diff HEAD > /tmp/work.patch, thensbx cpit out andgit applyit. -
Untracked files:
git ls-files -oz --exclude-standard | tar --null -T - -czf /tmp/untracked.tgz, thensbx cpit out.
sbx stop and sbx run factory keep everything, the factory's tickets included. sbx rm factory asks for confirmation, then deletes the clone, its worktrees and the factory's state for good, so get the work out first.
In a host-mounted sandbox the work is already on your computer: ticket branches are in your repository, and worktrees and the factory's state are under .factory/.
- Let running tickets reach handoff, or note where they are. The new sandbox starts with an empty factory, and tickets don't carry over.
- Push the branches the new sandbox should see. Its clone only has what's on GitHub.
sbx rm factory(it asks first). With a host mount, this leaves your files alone.- Create the sandbox as above, and copy
FACTORY.json,CONTEXT.mdand the files they reference in. - When you no longer need them, remove the old worktrees on the host (
git worktree list, thengit worktree remove <path>) and the rest of.factory/.
- The
shell-dockerbase, so agents get their own Docker daemon for tests, with Docker Hub allowed for pulling images - Latest Node.js 24.x, checked against
SHASUMS256.txt - pi, with
npmgoing through Socket Firewall (sfw npm) in bash, and its install telemetry (anonymous install and update reports, provider attribution headers) off. Turn it on in pi's/settings, or withPI_TELEMETRY=1. - Herdr as the entrypoint, with its pi integration and agent skill
- The
factorybinary from a factory-skills release, checked against the release's.sha256. It's the whole factory: the server, the stage skills, and pi's/factorycommand, widget and cards, whichfactory servewrites to~/.pi/agent/extensions/factory/each time it starts. There's no pi package to install.factory_version(kit arg, default0.6.4, at least0.6.0) is only the release a new sandbox starts on: the factory updates itself from there. factory-upand a startup hook that restarts the server at boot- GitHub CLI (
gh) - Fresh editor (
$EDITOR) - Hunk diff viewer and its
hunk-reviewskill for pi (hunk_versionkit arg, default0.24.1)
Run it from the repository root in any Herdr pane. It:
-
Prepares git. When
originis an SSH GitHub URL (git@github.com:…), it sends GitHub's SSH URLs over HTTPS in the sandbox user's~/.gitconfig(url.https://github.com/.insteadOf), because the proxy adds GitHub credentials to HTTPS only and the factory fetchesoriginbefore every ticket. The repository's own config isn't touched. It also adds/.factory/to the repository's.git/info/exclude, which is local and never committed, so the factory's worktrees stay out ofgit status. -
Creates
.factory/FACTORY.jsonif the repository has none. The starter config setsnameto the directory name,models.worktoanthropic/claude-sonnet-5-5,models.reviewtoanthropic/claude-opus-5-5, andserverto0.0.0.0:7731, or the next free port from7733when another repository's factory already uses7731(the dashboard listens on7732). SetFACTORY_WORK_MODELandFACTORY_REVIEW_MODELto choose other models (they must differ). Whenoriginis a GitHub remote, it also fills intracker(backlog labelfactory) andcodeHostwithpullRequests: false. An existingFACTORY.jsonis never rewritten, except for step 3. -
Makes the server reachable. It sets
server.hostto0.0.0.0when the host is missing,127.0.0.1orlocalhost, because a published port can't reach the sandbox's loopback. Any other host stays as you set it, with a warning. If a server is already running on the old host,factory-upasks you to stop it and run again. -
Starts
factory servein a Herdr workspace namedfactory(the server refuses to start outside Herdr). If a server already answers on/health, this step is skipped. Before that, it stops with an error when another repository in~/.local/state/factory/rootssets the sameserver.port, since the other repository's server would answer for this one. -
Writes the dashboard's token to
.factory/dashboard.env(mode0600):FACTORY_API_URL=http://127.0.0.1:7731 FACTORY_API_TOKEN=...
Tokens are shown only once, so
factory-upkeeps a token the server still accepts and replaces a revoked one. The token stays on the dashboard's server and never reaches the browser.
The kit publishes container port 7731 as factory-api; sbx ports factory shows its host port. The server speaks plain HTTP. If you change server.port, the published port no longer matches.
At boot, factory-autostart waits for Herdr (which starts when you attach), then runs factory-up again for each repository where it ran before: the workspace, and every repository factory-up listed in ~/.local/state/factory/roots. factory-up adds a repository there once its server is up, so one it rejected isn't restarted. Each needs its own server.port; remove a line from that file to stop restarting a repository. Its log is ~/.local/state/factory/autostart.log.
Project skills. pi finds skills in .pi/skills and .agents/skills, not in .claude/skills. If your repository keeps its skills there for Claude Code, point pi at them in the project's .pi/settings.json (paths there resolve from .pi/):
{ "skills": ["../.claude/skills"] }Linear tracker. With tracker.kind set to linear (factory-skills: Linear), give the sandbox your Linear API key on the host. The workload allows api.linear.app, and the proxy adds the key to requests to it:
sbx secret set-custom --sandbox factory --host api.linear.app --env LINEAR_API_KEY --value lin_api_...GitHub webhooks (optional). To verify webhooks, the server needs the secret named by codeHost.webhookSecretEnv, for example FACTORY_GITHUB_WEBHOOK_SECRET. sbx secrets only reach the sandbox as placeholders, so they can't verify an incoming signature. Pass the real value to factory-up:
FACTORY_GITHUB_WEBHOOK_SECRET=... factory-upThe factory server checks GitHub once a day for a newer release. When it finds one, pi shows a card and a footer line. To update:
/factory update in pi (add --when-idle to wait until no agent runs)
factory update in a shell
The server downloads the release's binary with gh, which uses the sandbox's GitHub token (sbx secret set github, as for a GitHub tracker), checks it against its .sha256, replaces ~/.local/bin/factory (keeping the old one as factory.previous), and restarts on it, adopting the running agents. Each open pi then asks for /reload to load the matching /factory. /factory update --rollback goes back. The new binary stays in the sandbox across sbx stop and sbx run; recreating the sandbox starts again from factory_version. See factory-skills: Updates.
Sandboxes made before the factory updated itself (factory_version below 0.6.0) can't run factory update, and they also have the factory-skills pi package, pinned to their release. Recreating the sandbox from this kit starts clean. To keep the sandbox, replace the binary by hand with the latest release (gh release download without a tag fetches it), in the sandbox:
arch="$(dpkg --print-architecture | sed 's/amd64/x64/')"
cd /tmp && gh release download -R geut/factory-skills \
-p "factory-linux-$arch" -p "factory-linux-$arch.sha256" --clobber
sha256sum -c "factory-linux-$arch.sha256" && install -m 0755 "factory-linux-$arch" ~/.local/bin/factory
factory --versionStop the server (Ctrl-C in its pane in the factory workspace) and run factory-up. The new server upgrades the factory's database (keeping a copy in .factory/db/), installs /factory, and names the pinned package once. Remove the package with the command it gives, then /reload pi:
pi remove git:github.com/geut/factory-skills@v0.4.1For mixin authors. The factory workload provides node@24 and io.github.geut/pi-factory@1. The single-pi kits provide neither, so a mixin that requires them only composes onto the factory. A mixin that requires io.github.geut/pi-factory >= 1 can rely on this:
factoryandfactory-upare onPATHfor theagentuser, in non-interactive shells too.- Herdr is the entrypoint.
factory serveruns in a Herdr pane, whichfactory-upopens. - After a restart, a startup hook reruns
factory-uponce Herdr is up, for$WORKSPACE_DIRand every other repository wherefactory-upran before. Until then the API refuses connections. - The server listens on container port
7731on0.0.0.0, published asfactory-api. factory-upwrites.factory/dashboard.env(mode0600) at the repository root, withFACTORY_API_URL, reachable from inside the sandbox, andFACTORY_API_TOKEN, anacttoken for thedashboardclient. It replaces the file only when the server rejects the token. For the sandbox's own repository, that is$WORKSPACE_DIR/.factory/dashboard.env.sfw(Socket Firewall Free) is onPATHfor theagentuser, in non-interactive shells too.- The sandbox has its own Docker daemon (the
shell-dockerbase), andagentcan use it. It can pull images from Docker Hub. - The image is Ubuntu 26.04, and its only apt sources are Ubuntu's archive,
download.docker.comandcli.github.com.
A change that breaks any of these bumps the major version. The name uses the io.github.geut/ namespace because bare names belong to Docker's com.docker.kit/ vocabulary.
The dashboard is such a mixin: it runs beside Herdr on container port 7732 and reads the factory through the server's REST API, using .factory/dashboard.env. The python kit is another.
Single-agent sandboxes that open pi directly:
| Kit | Image | Base |
|---|---|---|
| pi/ | ghcr.io/geut/sbx-shell-pi:node24 |
shell |
| pi-docker/ | ghcr.io/geut/sbx-shell-pi:node24-docker |
shell-docker (its own Docker daemon) |
sbx run --name pi ghcr.io/geut/sbx-shell-pi:node24 /path/to/your/projectSteps 1 and 3 of the factory setup apply here too.
Pass the kit directory instead of the image:
sbx run --name factory ./factory /path/to/your/projectsbx builds the directory with the OCI exporter, which Docker Desktop's default Buildx driver can't do. Use a docker-container builder, or turn on the containerd image store:
docker buildx create --name kits --driver docker-container --usePull requests that touch a kit build it with the kit frontend, which validates the descriptor, and run kit-tck validate on the result (the Validate kits workflow). The same workflow runs python/test-uv-sfw, the python kit's uv guard tests, with the uv version the kit pins; run it locally with python/test-uv-sfw [path/to/uv]. Building a kit proves its files were produced, not that they work, so also compose it onto its workload and try it before merging.
Merge the change to main, then run the Publish kits workflow from the Actions tab and pick one kit or all:
gh workflow run publish.yml --repo geut/sbx-shell-pi -f kit=factoryIt builds linux/amd64 and linux/arm64 in one Buildx call, pushes the image to GHCR, and checks the result.
To publish by hand, you need a GitHub token with read/write access to packages:
docker buildx build ./factory -f ./factory/factory.yaml \
--platform linux/amd64,linux/arm64 \
-t ghcr.io/geut/sbx-shell-pi:node-24-factory --pushUse ./pi with pi.yaml and tag node24, ./pi-docker with pi-docker.yaml and tag node24-docker, or ./python with python.yaml and tag python, for the other kits. The platform that isn't your machine's builds under QEMU. If it fails with Cannot open: Function not implemented, update the emulators with docker run --privileged --rm tonistiigi/binfmt --install all.
Based on Oleg Šelajev's article Building custom Docker Sandboxes.