| 1 | # Pi shell isolation and offline Go |
| 2 | |
| 3 | Paul approved this containment change on 2026-11-13 ("fix it all up"). This |
| 4 | controller design supersedes the Pi Bash exception in the connectors spec, |
| 5 | section 2.1, and the Pi deferral in the Engineering toolchain spec. |
| 6 | |
| 7 | Pi 1.5.2's `dist/core/tools/bash.js` calls `createLocalBashOperations`, then |
| 8 | spawns the configured shell. `dist/utils/shell.js:getShellEnv` copies the CLI |
| 9 | environment. Equipo supplies the provider key through the secret argument pipe |
| 10 | (`containment/mounts.go:addSecretEnv`); the credential home itself is never |
| 11 | mounted. The old shell could read that variable and the CLI's `/proc` files. |
| 12 | It also shared the relay at `127.0.0.1:18080` and `/egress/proxy.sock` |
| 13 | (`containment/egress.go`). Equipo's extension approved calls without adding a |
| 14 | sandbox. The previous `TestPiP4AStepCanReadTheKey` explicitly asserted this. |
| 15 | |
| 16 | Use Pi's existing `shellPath` setting, fixed to `/config/pi/bash`. No Pi patch |
| 17 | or package pin change is needed. In the pinned tree, |
| 18 | `dist/core/agent-session.js` uses `getShellPath()` both to construct the Bash |
| 19 | tool and in `executeBash`; `dist/utils/shell.js:getShellConfig` passes `-c` |
| 20 | and the command separately to the configured executable. Missing wrappers fail |
| 21 | closed. The wrapper passes the command as one argument to Bash after bubblewrap |
| 22 | has created the sandbox. It never evaluates the command in the CLI namespace. |
| 23 | |
| 24 | The wrapper uses absolute executable paths, including setup before isolation. |
| 25 | It starts bubblewrap through `env -i`, then clears the child environment again; |
| 26 | otherwise bubblewrap itself can retain the key in its process environment. |
| 27 | The wrapper is embedded in Equipo, checked against its compiled digest and |
| 28 | mounted read-only, with the pinned bubblewrap executable. It creates fresh |
| 29 | user, PID, network, IPC and UTS namespaces, drops capabilities, disables nested |
| 30 | user namespaces, clears the environment and mounts a fresh `/proc` and `/dev`. |
| 31 | The filesystem contains read-only `/usr` and `/etc`, a writable workspace and |
| 32 | shell-only temporary directory, and an empty home. The CLI's home, config, |
| 33 | package tree, key file, tool socket and relay socket are absent. Shell exit |
| 34 | also ends its background processes. Pi's native file tools are confined to the |
| 35 | workspace by a path check when each call is gated; its settings, model and MCP |
| 36 | files are individually mounted read-only. The containing directory stays |
| 37 | writable for Pi's settings lock. |
| 38 | |
| 39 | Pi gates every call in one assistant message before running them together, so |
| 40 | the gate-time path check alone could race a shell command that swaps a checked |
| 41 | path for a link. Equipo's extension therefore never lets a file tool and a |
| 42 | shell command run at the same time: whichever is gated second while the other |
| 43 | is still running is refused ("Run file tools and shell commands in separate |
| 44 | messages"). Calls of one kind still run in parallel, and separate messages run |
| 45 | in turn. TestPiBatchSeparatesShellAndFileTools covers both orders with a |
| 46 | positive control. The shell inherits only stdio (TestPiShellInheritedDescriptors). |
| 47 | |
| 48 | Engineering gets the same configured Go root and optional module cache as |
| 49 | Claude and Codex. A Pi attempt retains directory descriptors using the shared |
| 50 | Go pinning code; cleanup closes them. Only the Go root is hashed. Both outer |
| 51 | and inner mounts are read-only. The inner environment sets local toolchain, |
| 52 | offline module resolution and private scratch, disables Go environment files, |
| 53 | workspace discovery, telemetry and CGO, and ignores global Git configuration. |
| 54 | Review and answer roles keep their existing tool sets and get no Go mounts. |
| 55 | A missing module cache is omitted; an invalid existing cache is refused. |
| 56 | |
| 57 | The real pinned Pi runs against the existing local fake provider in tests. |
| 58 | Shell and Go-built probes test credential files, inherited and process |
| 59 | variables, TCP relay and Unix sockets. The same Go binary runs outside the |
| 60 | sandbox as a positive control, reporting only whether access succeeded. An |
| 61 | import from a prepared module cache proves offline `go test`; writes to both |
| 62 | trees must fail. Mutation checks remove each boundary and must fail its guard. |
| 63 | These offline probes do not replace provider release certification. |
| 64 | |
| 65 | The Pi policy format advances to `pi-v2`, so old policies cannot silently |
| 66 | retain the old shell behavior. No wire protocol or database migration changes |
| 67 | are needed. `origin/copy-specialist` already reserves protocol 21 and migration |
| 68 | 0081; this change consumes neither. Rollback uses the previous versioned |
| 69 | release and its matching certificates, restoring the old Pi shell limitation. |
| 70 | |