Skip to content

Run the real replay's variant code in the candidate sandbox - #219

Merged
MaxGhenis merged 11 commits into
mainfrom
claude/sandbox-real-replay
Oct 30, 2026
Merged

MaxGhenis merged 11 commits into
mainfrom
claude/sandbox-real-replay

Conversation

@MaxGhenis

@MaxGhenis MaxGhenis commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

The push-only real replay (uk-replay-determinism.yml) now runs a certified variant's third-party code only as uk_replay_sandbox.sh's unprivileged account, never as the runner user. A compromised package among a freeze's pins therefore cannot read PE_UK_PRIVATE_HF_READ_TOKEN out of the runner's memory with sudo, which #215 left open.

Problem

After #215, real-replay fetched the dataset before any variant code, then installed the variant's freeze and ran its engine as the runner user. That user has passwordless sudo, and the runner keeps the job's secrets in memory until the job ends. The tj-actions compromise read secrets from exactly there. The freeze pins versions, not file hashes, so the pins alone do not stop a changed package.

What changes

real-replay job. After the unchanged token step:

  1. The runner's own /usr/bin/python3 -I finds the fetched dataset by size and SHA-256 (find_dataset_bytes).
  2. uk_replay_sandbox.sh setup makes the account and its private copy, and checks the sandbox from inside (unchanged checks, plus the new offline ones below).
  3. install: the variant's exact freeze is built in the copy, in the sandbox, with the network and without the dataset.
  4. replay: no account process is left running. The account then writes the dataset into a freshly made input/ from a pipe, inside an offline service. Then it replays one measure-year with compute_uk_event --dataset-file, offline.
  5. collect (always): no account process survives, and output/ streams back.
  6. The runner's own /usr/bin/python3 -E -s -m pipeline.uk_replay_determinism compares the returned artifact with the committed one, which the job names.

The job has a 90-minute timeout. Nothing is uploaded or cached. The in-sandbox commands are in the new .github/scripts/uk_replay_determinism.sh.

Offline (in_sandbox --offline) is PrivateNetwork=yes, plus:

  • RestrictAddressFamilies=AF_INET AF_INET6 AF_NETLINK;
  • SystemCallArchitectures=native;
  • SystemCallFilter=~io_uring_setup io_uring_enter io_uring_register;
  • SystemCallErrorNumber=EPERM.

Each one is there because of something seen on a real runner or written in systemd's own docs:

  • With PrivateNetwork alone, busctl … ResolveHostname reached systemd-resolved over the system D-Bus socket and resolved example.com. DNS was a way out.
  • InaccessiblePaths=-/run stops the service starting (exit 226/NAMESPACE).
  • Denying AF_UNIX blocks D-Bus. socketpair(), spawn pools and ProcessPoolExecutor still work.
  • systemd filters socket(2) only. Its docs say RestrictAddressFamilies has no effect on the 32-bit x86 ABI (socketcall), and io_uring can open sockets without socket(2).

setup checks from inside an offline service that loopback is the only interface, that an IPv4 socket opens and a Unix socket does not, and that io_uring_setup fails with EPERM. The probe passes only by printing its last line.

Untrusted output. install and replay print the variant's output, stderr joined to stdout, inside ::stop-commands::<random token>. They first remove setup-uv's python problem matcher, which setup-uv v5 registers for the rest of the job.

The runner still honours the deprecated ::set-output; a probe step set one. The same command inside the fence set nothing and raised no annotation, and the runner masks the token in the log. Stderr has to be joined because the runner reads it as a second stream, where a last line without a newline arrives after the resume token.

pipeline/uk_replay_determinism.py. It is standard library only now, with its own canonical_bytes, so the runner's Python needs nothing installed. A replayed path that is not a regular file (a link to the committed artifact, say) is refused.

ci.yml real replay sandbox (new, on every PR, no secrets). It runs setup, install, replay and collect on the runner image with a stand-in dataset, a one-package freeze installed from PyPI in the sandbox, and a stub engine module in the copy.

The stub reports what it sees offline. It also leaves a process behind, forges ::error:: and ::set-output on stdout and (with no newline) on stderr, and prints a traceback shaped for setup-uv's matcher.

The runner's comparison must reproduce byte for byte its own expectation:

  • lo only;
  • no connection out, no name lookup, no D-Bus;
  • the stand-in's SHA-256;
  • a working pool;
  • the arguments the job passed.

A control step sets an output the deprecated way outside the fence, and the forged one must stay empty.

Docs. docs/uk_replay/RELEASE_REPLAY.md gets a new "The real replay in the sandbox" subsection under "Replay in CI", including what a malicious freeze can still do. The receiver section's "is weaker" paragraph becomes a pointer to it, and "Replay in CI" now counts four checks.

What a malicious freeze can still do

  • Leak through the log. It reads the dataset, as the engine must, and its output goes to the public log, so it could print household-level data there.
  • Fake the verdict. Its copy holds the committed artifact, so it can make the comparison pass. The check catches an honest engine that drifts, not a malicious one.
  • Use the network while installing. It has the network then, but no dataset.
  • Fail or stall the job, up to the timeout.
  • Leave data behind. It can leave files in /dev/shm and /dev/mqueue, and System V IPC objects, after collect; nothing later in the job reads them.
  • Use a kernel exploit. A kernel privilege escalation would defeat this sandbox, as it would any sandbox on the same kernel. install also runs without the system call filters.

Invariants (tested)

  1. The token stays where Keep the dataset token out of pull-request CI, and fetch it before any variant code #215 put it. Exactly three steps across all workflows hold it, and no pull-request workflow names it.
  2. Step order. In real-replay the fetch comes before any step that hands anything to the account. After it, the steps are exactly find → setup → install → replay → collect (always()) → compare, each gated on fetched. After the fetch, the only Python outside the sandbox is /usr/bin/python3 -I or -E -s, and no step uploads or caches anything.
  3. Exact sandbox arguments. Executed against a recording sudo stub, install and replay hand systemd-run exactly the base properties (plus the offline set for both replay services) and an environment of exactly the listed variables. The dataset path and the token are never in that environment.
  4. Order inside replay. It is pkill → in-sandbox hand-in (dataset bytes on stdin) → offline replay. Nothing runs as the account outside the sandbox, and nothing as root inside its home. With a surviving process it hands nothing in. A missing setting stops it before any sudo.
  5. The fence. The variant's stdout and newline-less stderr both land between ::stop-commands::<32 hex> and its token. The token differs on every run, and the exit status passes through.
  6. The in-sandbox script, under stub uv and engine. It runs exactly the freeze's three install commands. The replay's argv is exact, and only the replayed artifact (a regular file) returns. A failed engine returns nothing.
  7. Byte equality and stdlib only. Hypothesis checks canonical_bytes equals compute_uk_event.canonical_bytes byte for byte. The modules import under python -I -S, and the find step's own program reaches find_dataset_bytes under -I -S. -E keeps a PYTHONPATH impostor json out.
  8. The CI stub is pinned. Its report keys equal the expected keys, by ast. The expected values are loopback, no connections and pool 3, and the stub's Popen is a real call.

These mutations each fail a test:

  • dropping --offline, untrusted_output, 2>&1 or the survivor check;
  • moving the hand-in outside the sandbox;
  • comparing with -I;
  • dropping the symlink refusal;
  • removing a report key from either side.

Checked on real runners

  • Probes, no secrets (runs 39714152516 and 39715210775; the branch is deleted). Probe 1 found the D-Bus DNS leak; probe 2 checked that the chosen offline set closes it and that stop-commands holds, as described above.
  • This PR's CI before the syscall filters (run 39716509293, superseded by a push after all its steps had passed). real replay sandbox passed every step, and receiver sandbox passed with the offline checks.
  • Scratch branch with real freezes, no secrets (run 39720156794, branch deleted). Each end of the certified range (6.2.6 and 6.9.0):
    • installed its real freeze in the sandbox;
    • passed verify_installed and all six events' construction guards, offline, through the real replay mode;
    • ran the real replay command until it refused a stand-in dataset by digest.
  • Still to come: the real dataset's replay first runs in the push that merges this. I'll watch it.

Reviews

Two independent Opus 5.5 reviews (security, and workflow/test correctness); the Codex and Claude lanes were closed until about 07:15Z. Each re-checked its own findings against the final head.

  • Security found four issues, all fixed:

    • newline-less stderr escaping the fence;
    • setup-uv's matcher;
    • io_uring;
    • a setup probe that passed trivially.

    The 32-bit ABI gap came from systemd's docs.

  • Correctness found no bug in the step conditions, shell semantics or byte comparison. Its low items are all fixed:

    • a control step for the forged output;
    • a name-lookup probe;
    • timeouts, and a fresh input/ against a planted FIFO;
    • pins for four uncaught mutations;
    • the find step under the standard library alone.
  • Main's 13 later commits (a third Opus 5.5 review on 2026-10-30, at merge head 38e615f0; all six Codex lanes held). Those commits changed compute_uk_event.py and uk_replay_variants.py, which run inside the sandbox, and no earlier review saw them. It found no interaction problem: the merge leaves this PR's own files unchanged, the find step still imports under -I -S, the replay's import closure and variant freezes are the same, and the private copy still holds everything the replay reads. Its one limit: real replay sandbox stubs the engine, so the real engine first runs in this sandbox on the push that merges this.

Follow-ups (not here)

  • The receiver's run mode still prints the drain's output without the fence. Its step has no id, so a forged output reaches nothing, but annotations would show.
  • Ubuntu 26. ubuntu-latest moves to Ubuntu 26 from 19 October. Without a system Python 3.12, uv venv --python 3.12 downloads one, for ci.yml's replay-engine legs as much as here.

axiom: n/a: CI only

🤖 Generated with Claude Code

@vercel

vercel Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
policyengine-scorecard Ready Ready Preview Oct 30, 2026 2:31pm UTC

Request Review

MaxGhenis and others added 8 commits October 22, 2026 00:01
…only offline

Review of 1b6d3dc (security): the runner reads stderr as a second stream,
so a command there with no trailing newline arrived after the resume token;
setup-uv's python problem matcher reads plain lines that stop-commands does
not stop; io_uring opens sockets without socket(2), and per systemd's docs
RestrictAddressFamilies has no effect on the 32-bit x86 ABI. setup's offline
probe now passes only by printing its last line.
…ts, pins

Review of b359dd3 (correctness): the forged-output check would pass if
GitHub stopped honouring set-output, so a control step sets one outside the
fence; the stub also tries a name lookup, the channel seen leaking; both
jobs get timeouts, and the hand-in makes input/ afresh so a planted FIFO
cannot stall it; tests now pin stop_candidate's survivor check, the stub's
report keys against the runner's expectation, the stub's leftover process,
and the find step's program under the standard library alone. RUNNER_TEMP,
unused by the replay, is gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MaxGhenis
MaxGhenis force-pushed the claude/sandbox-real-replay branch from 497fb9a to 2e34d67 Compare October 22, 2026 04:01
@MaxGhenis
MaxGhenis changed the base branch from claude/peaceful-hertz-905cce to main October 22, 2026 04:01
MaxGhenis and others added 2 commits October 22, 2026 00:25
…links

Second security review of 2e34d67: "cannot read the token" holds short of
a kernel privilege escalation, and install runs without the system call
filters; the account can leave files in /dev/shm and /dev/mqueue and System
V IPC objects, which nothing later reads; a link at the copy's root still
moves the hand-in, but only within what the sandbox can write; the runner's
Python outside the sandbox runs with -E -s, not isolated mode; and the
timeout comment no longer claims more than the timeout does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…find test

Second correctness review of 2e34d67: the stub's newline-less stderr
fragment landed first and glued onto the matcher-shaped traceback, so the
merged stream never ended on the case the stderr join fixes; flushing
stdout first puts it last. The find-step test now picks the newest
certified variant, not any replay namespace.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MaxGhenis
MaxGhenis marked this pull request as ready for review October 22, 2026 04:32
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MaxGhenis
MaxGhenis merged commit 9ca2e6a into main Oct 30, 2026
14 checks passed
@MaxGhenis
MaxGhenis deleted the claude/sandbox-real-replay branch October 30, 2026 14:47

This branch was successfully deployed

1 active deployment
Preview — 38e615f0 Deployed Oct 30, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant