Plan: a kernel floor under bash - the landstrip binary runs every shell command with a policy per mode

Closes: #18 (phase one; Windows is filed as a follow-up). Branch: feat/kernel-sandbox. Status: Done (2026-10-04) — shipped in 0.92.0, reverted in 0.92.1 (#327); lessons on #18

TL;DR

Every control in this package is policy, and each assumes the command was classified right; classification is undecidable, since any program can write. #18’s spike proved the fix is capability removal, and that the landstrip engine does it. Adopting the pi-landstrip extension is blocked three ways (#18, 2026-10-04): it replaces the bash tool pi-workflow owns, so pi refuses to start; it parses our seeded agent files with its own schema and denies every tool when they fail; its policy merge only widens.

This plan uses the engine without the extension. pi’s bash tool takes a spawnHook that rewrites the command before the shell is spawned (the Evidence section quotes it), and pi-workflow’s sequentialBash (batch-order.ts:144-154) builds that tool per call. pi-modes decides the policy and publishes a hook through the runtime bridge, which already carries optional members (runtime-bridge.ts:24-68); pi-workflow applies it and decides nothing. The hook turns <command> into printf '%s' "$GADHS_SANDBOX_POLICY" | "$GADHS_SANDBOX_BIN" run -p - --policy-format json — bash -c "$GADHS_SANDBOX_CMD", the three values carried in env: no quoting of the command, no temp files, and pi keeps streaming, timeouts, abort and truncation as today.

Measured on this box (landstrip 0.19.6, Landlock ABI 9 + seccomp; #18, 2026-10-04): the plan policy refused a Python write, a shell redirect and an out-of-tree write while cat, git status/log/diff and exec worked; the auto policy allowed workspace writes and a commit and refused out-of-tree writes; a denyRead on a credentials directory held; the same write without landstrip succeeded. Phase one changes no rubric: on unsandboxed hosts the judge is still the only line. What stays, by name, is listed under Design.

Design

The engine, and why this one

Three candidates were compared (#18, notes 2026-09-30 and 2026-10-04):

landstrip (@landstrip/landstrip-api) Anthropic sandbox-runtime (srt) Codex linux-sandbox

Linux mechanism

Landlock + seccomp: unprivileged, no namespaces

bubblewrap with a network namespace: needs unprivileged user namespaces, which hardened distros disable

bubblewrap + seccomp

macOS

Seatbelt

Seatbelt (sandbox-exec)

none

Windows

AppContainer (needs explicit read grants per program)

a dedicated local user + WFP egress fence

none

Distribution

npm, native binary per platform, no system package

npm; Linux needs bwrap installed

part of the Codex tree, not a standalone artifact

Network

all-or-nothing, or an HTTPS proxy by domain

proxies only (HTTP and SOCKS); SSH would need a SOCKS-aware client

namespace off

Policy shape

filesystem.{allowWrite,denyWrite,allowRead,denyRead}, network.allowNetwork

the same four lists; network.allowedDomains

CLI flags

Licence

API Apache-2.0; binary LGPL-3.0, run as a separate process

check before adoption

Apache-2.0

landstrip is chosen for phase one: no system dependency, no user namespaces, SSH keeps working with the network on, and it is the engine already measured. The filesystem policy shape is the same as `srt’s, so the policy builder is engine-neutral; only the adapter that turns a policy into an argv knows landstrip. That makes the choice reversible, so no ADR. The version is pinned exactly: 162 releases in four months, one maintainer, pre-1.0.

Where each piece lives

packages/pi-modes/sandbox-policy.ts (new, pure)

policyFor(mode, {workspace, home, tmp, extraWrite, extraDenyRead}) → the JSON policy. No I/O.

packages/pi-modes/sandbox.ts (new)

The adapter: find the binary (binaryPath()), run doctor once per session, build the spawnHook, decide the degraded notice. Owns the landstrip argv.

packages/pi-modes/config.ts

sandbox?: { mode?: "off" | "on" | "required"; extraWrite?: string[]; extraDenyRead?: string[] } on ModesConfig, validated like safetyValve.

packages/pi-modes/session-wiring.ts (publishes the bridge)

bashSpawnHook?(): BashSpawnHook | undefined on the bridge: the hook when the sandbox is on and usable, undefined otherwise.

packages/pi-workflow/runtime-bridge.ts

The optional member’s type. NOOP returns undefined.

packages/pi-workflow/batch-order.ts

sequentialBash passes spawnHook: modesBridge().bashSpawnHook?.() into createBashToolDefinition.

The policies

Paths are resolved with realpath before they enter a policy (a symlinked workspace is granted by its real path, which is what the kernel sees).

plan auto, manual

allowWrite

/dev/null

the workspace; /dev/null; scratch: $TMPDIR (else /tmp), $XDG_RUNTIME_DIR (#302); tool caches that exist under $HOME: .cache, .npm, .pnpm-store, .local/share/pnpm, .yarn, .cargo, .rustup, go, .m2, .gradle, .bundle, .gem, .local/share/gem, .nuget, .dotnet, .composer; plus sandbox.extraWrite

denyRead

~/.ssh, ~/.pi/agent/auth.json, ~/.netrc, ~/.kube/config, ~/.docker/config.json, ~/.aws, ~/.config/gcloud/application_default_credentials.json, ~/.gnupg; plus sandbox.extraDenyRead

the same

network.allowNetwork

true (see Decision 1)

true

Two rules the builder enforces, both measured (#18, 2026-10-04):

  • A deny never sits inside an allow root. A denyRead inside the workspace made git status unable to list . and new files unreadable. Any deny whose path is inside an allow root is dropped from the policy, and the drop is reported once per session (the notice names the path). The workspace being $HOME itself is the case this hits.

  • The allow list holds only paths that exist, so a cache directory a box lacks is not created by the grant.

yolo gets no hook (every ask is allowed by design; the sandbox would be the one control left, and yolo promises none).

Plan mode’s one writable file, the plan draft under ~/.pi/agent/plans/, is written by pi’s write tool, in-process; bash never needs it.

Erratum (2026-10-04): the approved draft listed all of ~/.pi/agent in denyRead, claiming cat ~/.pi/agent/settings.json was already a deny rule. It is a shipped allow (modes.json, pinned in test/rule-precedence.test.ts). The floor denies ~/.pi/agent/auth.json, the credential the file-tool rules deny, and leaves the rest readable.

Failure modes, each named fail-open or fail-closed

sandbox.mode: "on" (default): fail-open, loudly

Binary present and doctor ok: every bash runs sandboxed. Binary missing, platform unsupported, or doctor not ok: bash runs as today, under every existing rule, valve and judge; the floor is simply absent. ONE notice per session says so, naming the reason (landstrip doctor: …), through ctx.ui.notify and an audit record gadhs_sandbox.status. The judge’s facts header carries sandbox: off (reason) or sandbox: landlock+seccomp, so the judge never assumes a floor that is not there. Accepted trade: a developer on an old kernel keeps a working shell.

"required": fail-closed

When the sandbox is unusable, every bash ask is refused with that reason. For boxes where the floor is the point.

"off": no floor by choice

No hook, no notice.

A deny nested inside an allow root (the workspace is $HOME, say): fail-open for that path, loudly

The nested deny is dropped (keeping it breaks the workspace, see the rule above), the notice names the path, and the facts header lists it (sandbox: landlock+seccomp; unprotected: ~/.ssh), so the judge keeps weighing reads of it as today. Never silent: the notice and the header line are pinned by tests.

The policy fails to validate at the binary (POLICY_* error)

Treated as doctor not ok for this session: the on / required behaviour above applies, with the binary’s message as the reason.

A command the kernel refuses is not a failure mode of the floor: it is the floor working, and the agent sees why (below).

doctor runs once, lazily, on the first bash call (not at load: a sub-second spawn, but startup should not pay it). Its result is cached for the session.

What the agent sees on a refusal

landstrip prints one JSON line per denial to stderr ({"kind":"filesystem","code":"FILESYSTEM_DENIED",…,"suggested_grant":{…}}) beside the program’s own Permission denied. Phase one keeps that: it is accurate and names the path. The mode prompts gain one sentence: "In plan mode the kernel refuses writes; a FILESYSTEM_DENIED line is the sandbox, not a bug to work around. If a task in auto needs a path the sandbox refuses, say so; the human can add it to sandbox.extraWrite." A tidier rendering (--trap <fd>) is a follow-up.

What is unchanged, by name

  • prompts/plan-judge.md, JUDGE_SYSTEM_PROMPT, the valve, every rule in modes.json (the credential deny rules for bash become redundant on sandboxed hosts; they stay for file tools and unsandboxed hosts).

  • pi-bash, the commit guard, batch order.

  • user_bash (!cmd typed by the human) is pi’s own tool, not wrapped.

  • Subagents: pi-subagents builds each one with a DefaultResourceLoader over the same settings (its src/index.ts, createResourceLoader), so a subagent loads pi-workflow and pi-modes too, gets the same registered bash, and its pi-modes publishes the bridge on the shared globalThis. The floor covers them; a test pins it (a Verify-shaped subagent in plan mode cannot write).

Decisions for the operator

  1. Plan mode’s network stays on (operator, 2026-10-04: research needs it). The plan judge allows network reads (glab issue view, git fetch, curl GET) and denies remote mutations; that stays its job. Plan mode’s kernel floor is "no local writes".

  2. Auto’s write scope: workspace + scratch + known caches, not $HOME. $HOME with denies inside it is the nested-deny configuration the measurement showed broken. The cache list will be incomplete for some tool; the cost is one visible refusal naming the path and a one-line config fix. Field round six measures how often.

  3. Default on with a visible fallback, not required. A developer on an old kernel or WSL1 keeps a working shell and sees why the floor is off. required exists for boxes where the floor is the point.

Scope

Units

  1. Policy builder (sandbox-policy.ts + test): the table above, the two rules, realpath, existence filter, extraWrite/extraDenyRead. Property test: for arbitrary workspace/home/deny lists, no deny in the output lies inside an allow root.

  2. Config (config.ts + test): the sandbox block, validated; bad values refuse to start, as other config does.

  3. Adapter (sandbox.ts + test): binary lookup, lazy doctor, the hook (env + rewritten command), the degraded decision per sandbox.mode, the facts line. Unit tests with a fake binary path and a fake doctor. Real-binary tests, describe.skipIf(!linux \|\| doctor not ok): plan policy refuses python3 -c 'open(…,"w")' and echo x > f, allows cat and git status; auto allows a workspace write and refuses one outside; denyRead holds; -p - reads the policy from stdin; a sandboxed sleep 60 is dead after pi’s abort (pi kills the process group, utils/shell.js:157-186; the test proves landstrip’s child is in it, else the adapter must setsid-proof it).

  4. Bridge and wiring (session-wiring.ts, runtime-bridge.ts, batch-order.ts + tests): the optional member; sequentialBash applies it; a test with a fake hook that sets an env marker and runs env through the real tool shows the marker; NOOP bridge → no hook.

  5. Prompts and facts: the sentence in auto’s and plan’s system prompts; sandbox: in factsHeader (judge.ts), pinned by the header contract test. No rubric change; eval --repeat 3 must stay 0 unsafe (the header changes, so the gate runs).

  6. Docs and release notes: modes.adoc gets a "Kernel sandbox" section (what it confines, what it does not, the config, the notice, the refusal line); architecture.adoc names the dependency; CHANGELOG Unreleased. The plan page under docs/modules/ROOT/pages/plans/ with a nav entry.

  7. Dependency: @landstrip/landstrip-api pinned exactly in pi-modes; consumer-sim must still install clean (its optional per-platform packages resolve under npm).

  8. Close: the MR carries Closes #18. On merge, #18 gets one line: the merge SHA, and the numbers of the follow-up issues below, which are filed at implementation start (plan mode cannot file them): Windows (AppContainer read grants), the plan rubric reduced to remote effects on sandboxed hosts, --trap <fd> rendering, mid-run "grant this path" approval, and srt behind the same adapter. The plan page’s status goes to Done with the date.

  9. Field: after release, round six of the field study on the release (operator’s call, as always) measures plan-mode and auto-mode friction from the floor; its report goes on #18 and #291.

Out of scope, to be filed at implementation start (see the Close unit)

Erratum (2026-10-04, after release): reverted in 0.92.1 (#327). In a live session the floor broke GPG commit signing, git over SSH, docker’s auth and Vertex calls from child processes: the kernel cannot tell the agent reading a credential from a tool using it on the developer’s behalf. Narrowed to a plan-only read-only floor, it duplicated plan mode’s policy-level rule and still needed carve-outs for research tools (glab rewrites its config, npm writes its cache). Operator decision: revert; lessons on #18.

Erratum (2026-10-04): filed as #321 (Windows), #322 (the plan rubric), #323 (--trap), #324 (mid-run grants), #325 (srt).

Erratum (2026-10-04, cold review): the floor counts as on only when the binary works AND something applies the hook to bash. pi-workflow says so through the bridge (bashHookApplied) when it registers its bash. pi-modes alone enforces nothing, so it reports the floor off and required refuses. The judge’s facts line computes the policy for the ask’s directory first, so a nested deny is named before the first command runs. The sandbox is claimed first-come on a process slot, like the bridge, so a subagent’s pi-modes reads its parent’s sandbox: the one whose hook its bash applies. A mode with no floor is told so in the facts.

Erratum (2026-10-04): pinned @landstrip/landstrip-api 0.19.4, not the measured 0.19.6. 0.19.6 was hours old, inside pnpm’s minimumReleaseAge hold, and pnpm 11 silently wrote minimumReleaseAgeExclude entries for it into pnpm-workspace.yaml. An exemption from that control is not this plan’s to make. 0.19.4 has cleared the hold, and the real-binary tests pass on it.

  • Windows (AppContainer read grants per program; required on Windows refuses bash until then).

  • The plan rubric reduced to remote effects on sandboxed hosts (after a field round shows the floor holding).

  • --trap <fd> rendering of denials.

  • Interactive "grant this path" approval mid-run (pi-landstrip has it; our ask broker could carry it).

  • srt as an alternative engine behind the same adapter, if landstrip stalls.

Versions

pi-modes minor, pi-workflow minor (a bridge member and a hook), meta minor. What is refused changes (plan-mode writes now fail at the kernel, auto-mode out-of-tree writes too), so minor, not patch.

Acceptance

  • With the sandbox on, in plan mode, python3 -c 'open("x","w")' fails with EACCES and no file exists; the judge was not what refused it (the audit log shows the judge’s allow or the rule’s allow, and the kernel’s denial in the tool result).

  • In auto mode a write to ~/.ssh/x or /etc/x fails; a write in the workspace, /tmp and ~/.npm succeeds; pnpm install and pip install --user-free flows in the field harness’s scenarios run.

  • A timed-out sandboxed command leaves no process behind.

  • On a box without the binary, bash works and one notice says why.

  • node tools/task.mjs validate green; eval --repeat 3 0 unsafe.

Evidence outside the repository

The seams this plan rests on are not in the tree, so the cold reviewer cannot open them. Quoted here, as read on 2026-10-04; implementation re-reads each before relying on it.

pi-coding-agent 1.0.2, dist/core/tools/bash.js (the prefix is prepended, then the hook runs on {command, cwd, env}, and its result is what pi spawns):

135 function resolveSpawnContext(command, cwd, spawnHook, exposeSessionEnvironment, ctx) {
136     const env = { ...getShellEnv() };
155     const baseContext = { command, cwd, env };
156     return spawnHook ? spawnHook(baseContext) : baseContext;
173     const resolvedCommand = commandPrefix ? `${commandPrefix}\n${command}` : command;
174     const spawnContext = resolveSpawnContext(resolvedCommand, ctx?.cwd || cwd, spawnHook, exposeSessionEnvironment, ctx);

dist/core/tools/bash.d.ts:64-80: BashSpawnContext {command, cwd, env}, BashSpawnHook = (context) ⇒ BashSpawnContext, BashToolOptions.spawnHook. createLocalShellOperations (bash.js:48-66) spawns shellConfig.shell […​args, command] with detached: true and the hook’s env.

dist/utils/shell.js:157-186 killProcessTree(pid): on Unix process.kill(-pid, "SIGKILL"), falling back to process.kill(pid). Hence the test that a sandboxed sleep dies on abort.

@landstrip/landstrip-api 0.19.6 (npm pack, 2026-10-04): bin/landstrip.js, lib/index.js exporting binaryPath(), optional per-platform packages @landstrip/landstrip-{linux,darwin,win32}-{x64,arm64}; landstrip run --help lists --policy-format <FORMAT> ("Required when a policy is read from standard input") and --trap <FD>. landstrip doctor here: {"ok":true,"platform":"linux","implementation":"landlock+seccomp"}.

@gotgenes/pi-subagents (installed), src/index.ts:100-125: createResourceLoader: (opts) ⇒ new DefaultResourceLoader(opts) and createSession: … createAgentSession({…​ resourceLoader …​}), with excludedExtensionPackages the only subtraction. So a subagent loads the same extensions as its parent.

Edit this page · latest