gvisor demos: design note rev 1 and builder-check brief
Design for running anonymous demos and demo builds under gVisor (runsc), from the 2026-11-07 spike and Paul's 2026-11-08 rulings (#527).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+365
−0
docs/superpowers/reviews/CODEX-REVIEW-BRIEF-gvisor-demos-design.md+85 −0docs/superpowers/specs/2026-11-08-gvisor-demos-design.md+280 −0
CI passed — run details
Intent
diff --git a/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-gvisor-demos-design.md b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-gvisor-demos-design.md| new file mode 100644 |
| index 000000000..91cd3c341 |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-gvisor-demos-design.md |
| @@ -0,0 +1,85 @@ |
| +# Review brief: gVisor demos design note, round 1 of 3 (builder-check) |
| + |
| +Repo carlos/platform, branch `gvisor-demos`, the commit named in your prompt. |
| +Under review: `docs/superpowers/specs/2026-11-08-gvisor-demos-design.md`. |
| +Authorities: the code on this branch (cut from main 9622c65a). Background |
| +evidence, not authority: `~/.cache/gvisor-spike/REPORT.md` and |
| +`~/.cache/gvisor-spike/astra-integration.md` (your own read-only analysis |
| +from 2026-11-07). Do not review against unmerged branches; if this work |
| +needs one, say so as a P1 and stop. |
| + |
| +You are an independent reviewer and the builder who will implement this. |
| +Read the note, then the code it names, and check every claim against that |
| +code. The question is: could you build this as written, and would it be |
| +safe? Name what is missing or wrong that would stop or mislead an |
| +implementer. |
| + |
| +## Fixed: do not re-argue |
| + |
| +- Paul's rulings, §2 of the note (recorded on #527, 2026-11-08). Report |
| + only mechanisms that fail to honour them. |
| +- Scope is demos only (§3). Networked gVisor is out. |
| +- §4.1 (`auto` resolves to systemd in this build, explicit `gvisor` on the |
| + dev demo box) is a sequencing decision to keep flagship demos untouched. |
| + Report only if it fails to honour a ruling's end state or the flagship |
| + rule. |
| + |
| +## What to check |
| + |
| +1. Root trust boundary: does the bundle writer (§6.3) or any other new root |
| + path read, open, follow or run anything a tenant, an app or a box agent |
| + can create, write or name? Is "the trampoline inside the sandbox reads |
| + the launch JSON" (§6.4) actually how today's trampoline works |
| + (`internal/instanceexec`), and does it run unchanged as uid carlos under |
| + runsc with an empty rootfs? |
| +2. No fallback (ruling 5): is there any start, generation, wake, probe, |
| + build, claim-freeze or recovery path that names a native template |
| + directly and would bypass `unitFamily` (§7)? List them with file:line. |
| +3. Agent/root agreement (§4): do activator identity, `unitproc`, names |
| + parsing, stop and sweep paths need more than the note says to hold the |
| + right unit family for a handle's lifetime? |
| +4. runsc supply (§5): is the release-asset + pointer + `ensureRunsc` path |
| + implementable on today's release, console mirror and box system-update |
| + code? Is the pointer change additive for boxes and consoles on older |
| + versions? Is "only when effective mode is gvisor" safe for bootstrap |
| + ordering on a fresh demo box? |
| +5. Limits (§6.2) and demo policy readback: do `assertDemoUnit`, |
| + `demoSizeShown`, `demoCgroup`, slice sizing and overlap/generation |
| + budgeting (`instancectl/gen.go`, `server.go`) all get the +32 MiB |
| + consistently, or will one of them refuse every gVisor start? |
| +6. Stop/exit (§6.5): with MainPID = runsc, do exit records, `observe`, |
| + `finaliseGen`, `freezeDemoLocal` and demo cleanup keep their proofs? |
| +7. Demo build (§9): is the fixed-uid-plus-chown approach compatible with |
| + `internal/demobuild` layout, mounts and output validation? |
| +8. Census and cross-compile: anything in the note that would put cgo, |
| + Linux-only types in CLI-linked packages, or an unpinned file in root's |
| + scope? |
| + |
| +## Severity |
| + |
| +- **P1**: unsafe, would not compile, a test fails, or it would not work. |
| + Blocks merge. |
| +- **P2**: wrong or missing. Fixed without reopening this review. (The |
| + census, and review of any newly changed security, root, termination |
| + or production-storage behaviour, still check the fix; see AGENTS.md, |
| + "Stopping rules".) |
| +- **P3**: clarity or polish. Goes on a follow-up list; never a reason for |
| + another round. |
| + |
| +A P1 states its failure scenario and the evidence (file:line). Do not |
| +raise a P2 to P1 to keep the review open. |
| + |
| +## Output |
| + |
| +Findings ranked P1, P2, P3. Each gives the section, the problem, the |
| +evidence (file:line, verified), the failure scenario, a concrete fix and |
| +the invariant or trust boundary it breaks (that is its fault family). End |
| +with exactly one verdict: |
| + |
| +- **READY**: no P1 and no P2. |
| +- **READY AFTER FIXES**: no P1. The listed P2s are fixed without another |
| + round. |
| +- **NOT READY**: one or more P1s, listed. |
| + |
| +Do not edit files. Do not spawn Anthropic-model reviewers or subagents of |
| +your own. Do not run the full test suites. |
diff --git a/docs/superpowers/specs/2026-11-08-gvisor-demos-design.md b/docs/superpowers/specs/2026-11-08-gvisor-demos-design.md| new file mode 100644 |
| index 000000000..681a62929 |
| --- /dev/null |
| +++ b/docs/superpowers/specs/2026-11-08-gvisor-demos-design.md |
| @@ -0,0 +1,280 @@ |
| +# gVisor sandbox for anonymous demos: design (2026-11-08, rev 1) |
| + |
| +Discussion: amadan carlos/platform #527. Spike: `~/.cache/gvisor-spike/REPORT.md` |
| +and `astra-integration.md` (2026-11-07, runsc release-20261102.0, systrap, t4g). |
| +Branch `gvisor-demos`. This note decides the shape; the plan carries the code. |
| + |
| +## 1. What a user gets, and when |
| + |
| +Code a stranger hands the /start demo runs under gVisor: its syscalls are served by |
| +runsc's user-space kernel, not the host kernel. The demo build (the offline |
| +`go build` of a stranger's source) runs there too. Visible change: `carlos status |
| +--layout` names the sandbox per box and per instance, and a demo on the dev demo box |
| +wakes about 100 ms slower. |
| + |
| +Switch-on: the dev demo box in this branch's dev witness (§11). Flagship demos switch |
| +on in a later window owned by the flagship /start go-live (coordinators 55f1f6a4, |
| +582c99b6, 448bfd5a), not here. |
| + |
| +## 2. Paul's rulings (2026-11-08, fixed) |
| + |
| +1. Demos first. Shared pools only after outbound networking is re-proved under gVisor. |
| + Not built here. |
| +2. Absorb the 25 to 30 MB per instance: the demo instance gets more memory so the app |
| + keeps its effective 256 MB. No charge. |
| +3. Operator switch `CARLOS_EXEC_SANDBOX=auto|systemd|gvisor` in root-owned host.env, |
| + undocumented until shared pools use it. `auto` = gVisor on demo boxes only. |
| +4. Our own pinned, checksummed runsc through the platform's release channel. A box |
| + upgrade never changes it silently. |
| +5. In gVisor mode, refuse tty sessions, rootfs apps and the shelved host-claims mode. |
| + Never fall back to native when the effective mode is gVisor. |
| + |
| +## 3. Non-goals |
| + |
| +Networked instances under gVisor (shared pools, ordinary apps), claim-mode units |
| +(`claimunit_*`), tty/cmd/seed/sidecar roles, rootfs templates, runsc checkpoint or |
| +restore, KVM platform, a gVisor apt repo, public docs for the switch. |
| + |
| +## 4. The switch (one parser, one resolution) |
| + |
| +New package `internal/execsandbox`: |
| + |
| +- `Parse(getenv) (Configured, error)`: unset or `auto`, `systemd`, `gvisor`. Anything |
| + else is `EXEC-SANDBOX-CONFIG` and blocks every instance start on the box (root |
| + refuses Ready; the agent logs it once and refuses wakes with that reason). |
| +- `Resolve(configured, demoBox bool) Effective`: `systemd` → systemd; `gvisor` → |
| + gvisor; `auto` → see §4.1. |
| +- Root (`carlos-instance-control`) and the agent each resolve once at process start |
| + from host.env. The value is fixed for the process lifetime; changing it is a |
| + host.env edit plus the restart that edit already needs. |
| +- Root is the authority. `Ready`/`ReadyDemo` and every start response carry root's |
| + effective mode (additive field). The agent refuses to start if its own resolution |
| + differs, with `EXEC-SANDBOX-MISMATCH`; it never picks a unit family on its own. |
| + |
| +`gvisor` on a box that is not a demo box: every instance start is refused with |
| +`EXEC-SANDBOX-UNSUPPORTED` (networked instances are not built). Not a fallback: the |
| +operator asked for gVisor, so nothing runs natively. |
| + |
| +### 4.1 `auto` in this build (deviation for the flagship rule, flagged to platform-f6) |
| + |
| +Ruling 3 says `auto` means gVisor on demo boxes. Shipped as-is, the next flagship box |
| +roll would switch flagship demos to gVisor, which the go-live owners forbid. So this |
| +build lands `auto` resolving to systemd everywhere, and the dev demo box gets an |
| +explicit `CARLOS_EXEC_SANDBOX=gvisor` in its host.env for the witness. A one-line |
| +follow-up (`auto` → gVisor when `demoBox`) lands when the flagship go-live owners give |
| +the flagship gVisor window; its flagship roll is that window. The resolution function |
| +and tests carry both behaviours behind one constant so the follow-up is that line and |
| +its test. |
| + |
| +## 5. runsc supply (ruling 4) |
| + |
| +- **Pin in the tree:** `internal/execsandbox/runsc.lock.json`, embedded: gVisor release |
| + name, upstream tarball sha512 per arch, and the sha256 of the extracted `runsc` |
| + binary for `linux-arm64` and `linux-amd64`. Changing runsc is a reviewed commit to |
| + this file and nothing else. |
| +- **Release assets:** the release cut fetches the upstream tarballs, checks sha512 |
| + against the lock, extracts `runsc`, checks its sha256 against the lock, and attaches |
| + `runsc-linux-arm64` and `runsc-linux-amd64` to the GitHub release, listed in the |
| + signed SHA256SUMS like every other asset. A release-check test reads the lock so a |
| + cut cannot attach a different binary. |
| +- **Mirror and pointer:** `carlos system update` (console `runSystemUpdate`) mirrors |
| + `runsc-<plat>` for each platform it mirrors `carlos-<plat>` for, to |
| + `bootstrap/router/<tag>/runsc-<plat>`, and records it in the signed pointer: |
| + `SystemRelease.Runsc map[string]SystemArtifact` (additive, omitempty; old pointers |
| + parse; boxes ignore it when absent). Uploads by `--file` carry no runsc. |
| +- **Install on the box:** the root system-update path and bootstrap call one function, |
| + `ensureRunsc`, but only when the box's effective mode is gvisor. It downloads the |
| + pointer's artifact, requires pointer sha == compiled pin sha, and installs it |
| + root-owned 0755 at `/opt/carlos/runsc/<sha256>/runsc` by write-to-temp, fsync, |
| + rename. The directory name is the hash, so an upgrade with a new pin installs a new |
| + path beside the old one and never rewrites a binary in use. Old directories go once |
| + no unit references them. |
| +- **Use:** root checks the installed file's sha256 against its own compiled pin at |
| + Ready (and caches by dev/inode/size/mtime). Missing or mismatched: Ready fails with |
| + `EXEC-SANDBOX-RUNSC` and every start is refused. Units reference the path through a |
| + root-written drop-in, so the template stays fixed. |
| + |
| +## 6. Units and the bundle |
| + |
| +### 6.1 Templates (embedded in `internal/host/units`) |
| + |
| +- `carlos-instance-gvisor@.service` and `carlos-instance-gvisor-gen@.service`. Demo |
| + boxes run only the main and generation roles today; every other role stays refused. |
| +- `carlos-demo-build-gvisor@.service` (§9). |
| +- `carlos-instance-gvisor-probe.service` (§8). |
| + |
| +Shape, from the spike: `User=root`, `Type=exec`, same per-host slice, restart and |
| +stop-dependency policy as the native template, and |
| + |
| + ExecStartPre=<runsc> --root=/run/carlos-runsc delete -force <id> |
| + ExecStart=<runsc> --root=/run/carlos-runsc --ignore-cgroups --network=none \ |
| + --host-uds=create run --bundle /var/lib/carlos-control/oci/<id> <id> |
| + ExecStopPost=<runsc> --root=/run/carlos-runsc delete -force <id> |
| + |
| +`<id>` is derived by root from the validated unit instance name (host, role, |
| +generation) and never reused while an older invocation of it may survive. With |
| +`--ignore-cgroups`, runsc, Sentry, gofer and helpers all sit in the unit's cgroup, so |
| +systemd's limits and the cgroup-empty termination proof cover the whole sandbox. |
| +Host-side hardening is the measured compatible set (plan task: establish it on the |
| +root runner, then pin it in the verifier); it is not copied from the native template. |
| + |
| +### 6.2 Limits (ruling 2) |
| + |
| +`execsandbox.GVisorOverhead = 32 MiB` (spike: +25 to 30 MB). For a gVisor demo unit |
| +and its per-host slice: MemoryMax = small + 32 MiB, MemoryHigh = HighOf(that), |
| +MemorySwapMax = MemoryMax, TasksMax = small + 64 (spike: +30 tasks). CPU and IO stay |
| +the small tier's. `GOMEMLIMIT` = 90% of the small tier's 256 MiB is set in the guest |
| +environment (§6.4), because the app cannot see `memory.max` inside the sandbox. |
| +`assertDemoUnit`, `demoSizeShown` and `demoCgroup` compare against these values in |
| +gVisor mode and the native values otherwise. |
| + |
| +### 6.3 Bundle writer: root derives everything |
| + |
| +`internal/instancectl/ocibundle.go`: one typed constructor, `gvisorBundle(host, role, |
| +gen)`, run by root before `systemctl start`, writing |
| +`/var/lib/carlos-control/oci/<id>/config.json` (0600 root, parent 0700) with an empty |
| +read-only rootfs shared at `/var/lib/carlos-control/oci/rootfs` (not under `/run`: |
| +noexec breaks the gofer, spike gotcha 1). |
| + |
| +Inputs are the validated host shape, role and generation. No tenant-writable byte is |
| +read by root to build it: not the launch JSON, not the app's files. |
| + |
| +- Process: the platform's own trampoline, the same argv the native template's |
| + ExecStart uses today, plus `--sandbox=gvisor`. uid/gid carlos, no capabilities, |
| + `noNewPrivileges`, cwd the instance data dir. |
| +- Mounts: the root-owned carlos binary (ro), `/opt/carlos/live/<host>` (ro), the |
| + instance's nested data dir and run dir (rw), tmpfs `/tmp`. Nothing else from the |
| + host. Sources are derived from the host shape exactly as the native template's |
| + paths are; the writer refuses if any source is a symlink or not owned as expected. |
| +- Network: none (`--network=none`, loopback only). |
| +- The writer writes then reads back and compares bytes; `assertGVisorUnit` (§7) |
| + rebuilds the expected bytes and compares again before start. |
| + |
| +### 6.4 The trampoline inside the sandbox |
| + |
| +The tenant-writable launch JSON is consumed where it is today: inside the sandbox, by |
| +the trampoline running as carlos. Root never parses it. With `--sandbox=gvisor` the |
| +trampoline keeps validation, the launch binding, the pinned executable and exit |
| +records, and: |
| + |
| +- skips host-kernel Landlock abstract-socket scoping: the abstract namespace is per |
| + sandbox (spike), and the probe (§8) proves a host abstract socket is invisible; |
| +- sets `GOMEMLIMIT` in the app's environment to the root-supplied value, overriding |
| + the launch's; |
| +- is PID 1 of the guest, so it keeps reaping and signal forwarding. |
| + |
| +### 6.5 Stop, exit and stale state |
| + |
| +`KillMode=mixed`: SIGTERM to runsc, which forwards it to the guest init (trampoline), |
| +which forwards to the app; SIGKILL to the cgroup after `TimeoutStopSec`. The root |
| +runner proves graceful stop and the kill path. The trampoline writes the exit record |
| +inside the guest as uid carlos, as today, so the activator's exit reading is |
| +unchanged; systemd's own result describes runsc and is advisory. Termination proof |
| +stays systemd invocation state plus an empty cgroup. `runsc delete -force` runs before |
| +start and after stop (spike gotcha 2); the generation finaliser also removes the |
| +bundle directory after the proof, before any reuse of the id. |
| + |
| +## 7. Root policy in gVisor mode (ruling 5, no fallback) |
| + |
| +One function picks the unit family: `unitFamily(effective, role, route) (family, |
| +error)`. Every start, generation, probe and build path goes through it; there is no |
| +second place that names a template. In gVisor mode it returns an error for: |
| + |
| +- tty, cmd, seed, sidecar roles (`EXEC-SANDBOX-ROLE`; already refused on demo boxes); |
| +- a rootfs route (`EXEC-SANDBOX-ROOTFS`); |
| +- any start while host claims are enabled (`hostwrite.Enabled`): Ready fails with |
| + `EXEC-SANDBOX-CLAIMS`, so the box never serves in that combination; |
| +- a non-demo box (§4). |
| + |
| +`assertDemoUnit` gains a gVisor branch, `assertGVisorUnit`: `systemctl show` readback |
| +of User=root, the exact ExecStart/ExecStartPre/ExecStopPost, runsc path and pin |
| +directory, Slice, limits from §6.2, no pending reload, plus the bundle byte |
| +comparison. The native demo drop-in (`demo.conf`: PrivateNetwork, AF_UNIX, tmpfs over |
| +`/run` and `/var`) is not applied to gVisor units; it would hide the bundle and |
| +runsc state. Its offline guarantee is replaced by `--network=none` in the asserted |
| +ExecStart and the probe. |
| + |
| +Mode change: at Ready, root refuses (`EXEC-SANDBOX-DRAIN`) while any unit of the other |
| +family is active or has a non-empty cgroup, and sweeps leftover runsc state and bundle |
| +directories for units that are inactive and empty. An operator flips the switch with |
| +the box drained; a box with demos running reports the block instead of mixing. |
| + |
| +## 8. Readiness probe |
| + |
| +`carlos-instance-gvisor-probe.service` uses the real bundle writer with a probe role |
| +and the trampoline's probe mode. Inside the guest it checks: uid/gid carlos; CapEff 0; |
| +NoNewPrivs; the kernel is gVisor's (`uname` release and `/proc/version` as runsc |
| +reports them); `io_uring_setup` gives ENOSYS; no interface but loopback and a TCP |
| +connect to a public address fails; a host abstract socket created by root before the |
| +probe is not reachable; a file outside the mounts is absent; it can create its socket |
| +on the host run dir and root connects to it. Root also checks the probe unit's cgroup |
| +contained runsc and its children and is empty after. `ReadyDemo` requires a pass on |
| +the current runsc pin; a failed probe blocks starts with its reason. |
| + |
| +## 9. The demo build |
| + |
| +`carlos-demo-build-gvisor@.service`: root runs runsc with a build bundle from the same |
| +writer family (`gvisorBuildBundle`): toolchain and module cache ro, source ro, work, |
| +output, cache and tmp rw, cwd `/work/src`, the exact offline argv and environment of |
| +today's `carlos-demo-build@` (GOTOOLCHAIN=local, GOPROXY=off ...), plus |
| +`GOMEMLIMIT` = 90% of the build's memory. The compiler runs as a fixed unprivileged |
| +uid inside the guest (DynamicUser has no meaning there); root chowns the per-build |
| +work tree to it before start. `Type=exec` with `RuntimeMaxSec=300` (native 180; the |
| +spike's cold build took 1.5x as long), MemoryMax 1 GiB + 32 MiB, TasksMax 128 + 64, |
| +CPU as today, `KillMode=control-group`. `internal/demobuild` `prepareUnit`, `runUnit`, |
| +`assertUnit`, `cleanUnit` and recovery branch on the family; output validation, |
| +diagnostics and the aggregate build slice are unchanged. The build probe runs the |
| +gVisor build unit when the box is in gVisor mode. |
| + |
| +## 10. Demo claims keep working |
| + |
| +A claim freezes the demo (`freezeDemoLocal`: stop and prove), then root snapshots the |
| +host DB and WAL (`wireDemoClaimSnapshot`). In gVisor mode the stop-and-prove covers |
| +the gVisor unit family, waits for the cgroup to empty and for `runsc delete` to |
| +finish, then the snapshot reads the host-visible files, which are the same files the |
| +guest wrote through the gofer. Demo instances hold a local lease with no replicator, |
| +so no host process reads the DB while the guest writes it. A root-runner test runs a |
| +demo under gVisor, writes rows, freezes, snapshots and checks integrity and content. |
| + |
| +## 11. Reporting |
| + |
| +`status.LayoutReport` gains `ExecSandbox {Configured, Effective, Runsc (version and |
| +sha256), Ready, Blocked}`, and `RowLayout` gains `Sandbox` (`systemd` or `gvisor`, |
| +from the unit family the activator holds). Additive; an old report means unknown. |
| +`carlos status --layout` prints one line per box and a column per instance. |
| +`docs/site/cli.md` names nothing new (no new command); the switch stays undocumented. |
| + |
| +## 12. Verification |
| + |
| +- Unit tests with fake systemctl: parse/resolve table; no-fallback (every refused |
| + combination, and the absence of any native start in gVisor mode); bundle bytes are |
| + a pure function of (host, role, gen); verifier rejects each mutated property; |
| + limits; status fields; pointer round-trip with and without `Runsc`. |
| +- Root runner (`//go:build linux && rootrunner`, throwaway arm64 EC2, runsc from the |
| + lock): start and serve over the host socket; SIGTERM graceful stop; kill -9 then |
| + restart with zero acked writes lost; memory overrun oom-kills the whole unit; probe |
| + passes and each probe check fails when its property is broken; demo build output |
| + matches the native build; claim freeze and snapshot under gVisor; mode drain. |
| +- Dev witness (§13). |
| +- Census: `make census-card` / `census-propose`, Opus verdict on #280. |
| + |
| +## 13. Rollout |
| + |
| +1. Merge with `auto` → systemd (§4.1): no box changes mode on its next roll. |
| +2. Root-runner witness passes on the merged SHA. |
| +3. Release carrying runsc assets: needs Paul's quoted go via the design session, |
| + version and window from agent manager 8a3d302, #421 rules (one live window, one |
| + release line). |
| +4. Dev demo box: set `CARLOS_EXEC_SANDBOX=gvisor` in host.env, ride a roll restart; |
| + check probe, `carlos status --layout`, a demo create, build, wake, and a claim. |
| + Rollback: remove the line and restart (the drain check covers leftovers). |
| +5. Flagship: not here. |
| + |
| +## 14. Risks |
| + |
| +- Root launch authority grows (bundle writer, runsc as root). Contained by §6.3: root |
| + derives every field from the validated host shape and reads no tenant byte. |
| +- runsc failures surface as "sandbox exited". The probe and the start path log the |
| + runsc debug line from the unit journal with the refusal. |
| +- The follow-up flip in §4.1 is a dormant default (rule 5). Its switch-on is the |
| + flagship gVisor window after go-live; the dev box runs it from step 4. |