Skip to content

Security: EngFlow/any2bazel-lab

Security

SECURITY.md

Host safety

Inner agents run unattended with --dangerously-skip-permissions, network access, and a shell. They read untrusted text: target repos, their READMEs and CLAUDE.md files, and package contents. They also download and execute code: build tools, registry modules, and release binaries (one early run ran Doxygen and buildifier downloaded from GitHub). This document ranks what can go wrong on this machine, records what is in place with the evidence that it works, and names the gaps.

Perfect safety is not the goal. The goal is cheap mitigations whose cost to efficiency, and to the fidelity of the experiments, is known and recorded. One exposure is left for each operator to decide before the first run: the runner's Claude credentials, in the last section.

Threats, ranked

# threat how it would happen status
1 Credential theft or misuse a prompt injection in a repo or package, or a malicious dependency. An agent running as the operator could read ~/.ssh/id_ed25519 (which lets it push to the operator's GitHub), the gh token, and Claude credentials mitigated: inner agents, reference builds, and verification run as runner (section 3). The runner's own Claude login stays within an inner agent's reach (the last section)
2 Malicious dependency registries and maintainers get compromised, and builds and agents pull "latest" partly mitigated: cooldowns (section 1)
3 Host starvation parallel Bazel servers exhausting RAM, CPU, or disk; the OOM killer taking the operator's own session mitigated: per-run and all-runs cgroup caps, disk floor (section 2)
4 Lab tooling damaging the host destructive commands in the lab's scripts low. The deletions in the lab's scripts are the old skill copy that install_skill.sh swaps out, temp dirs, and a finished run's originals on the runner's side. to_holding.sh removes those originals as runner, only after it has copied and counted them, and it validates their paths against the expected shapes first

1. Supply-chain cooldowns (in place)

A version published in the last 7 days is not installable. Compromised releases are usually detected and yanked within days.

ecosystem mechanism verified
npm (and npx, which uses npm config) min-release-age=7 in ~/.npmrc. The value is in days. It needs npm 11.13 or later: earlier versions accept the setting and ignore it positive controls: an install with min-release-age=100000 fails with ENOVERSIONS whether the setting comes from the user .npmrc, a project .npmrc, or the environment variable. With 7, a normal install succeeds. ⚠ npm config get min-release-age prints null even when the setting is set, so verify it by behavior
Bazel modules ~/.bazelrc has common --registry=file://~/.cache/bcr-snapshot. The snapshot is a local clone of the BCR, checked out at the newest commit that is at least 7 days old (tools/cooldown/refresh_bcr_snapshot.sh) bazel_bats@0.40.0, published after the snapshot, fails to resolve, and @0.38.23 resolves. Both resolve against the public BCR. Archives are still fetched from upstream, but they are checked against the snapshot's integrity hashes

The runner has the same two cooldowns, in root-owned configs (/srv/a2b/runner-config, section 3) that point at the runner's own snapshot in /srv/a2b/bcr-snapshot.

tools/preflight.sh fails a launch unless, for both the runner and the owner, npm's minimum release age is at least 7 days and the BCR snapshot is between 7 and 30 days old (tools/cooldown/check_cooldowns.sh, tested with synthetic 1-, 10-, and 40-day snapshots). Refresh both snapshots between studies. Inside a study the snapshot is a frozen condition (STUDIES.md section 4). Either refresh it only between targets and never between the arms of a pair, or list it as frozen for the whole study.

tools/cooldown/refresh_bcr_snapshot.sh                # the owner's
tools/runner/sync_runner_tools.sh --snapshot-only     # the runner's; without the flag it also takes your current claude and node

Gaps (not covered, and why)

  • pip / PyPI. Venvs get pip 24.0, which has no age gate. Newer pip and uv have options for one, but neither is what agents get by default. One early run built a pip venv.
  • Cargo, Go modules, Maven, Gradle. None has a built-in age gate. The remedy is a proxy or mirror with an age policy, which is not cheap. Lockfiles (Cargo.lock, go.sum) mean that existing projects resolve pinned versions, so the exposure is agents adding or upgrading dependencies.
  • Anything outside a registry: http_archive with a URL, curl, wget, git clone, GitHub release binaries. Prevention needs network egress control. No tool detects these downloads. A run's transcript records every command the agent ran, so they can be found there afterwards.
  • Override by the agent. A project .npmrc or --registry=https://bcr.bazel.build on a command line defeats the cooldown. The runner's user-level configs are root-owned, so the runner can't edit them, but project-level overrides remain possible. collect_run.sh greps every transcript for bypasses.
  • pnpm / Yarn / Bun have their own age settings, but none of them is installed. Corepack could fetch them.
  • Bazel itself. /usr/local/bin/bazel is Bazelisk (v1.28.1). It downloads whatever Bazel release a project's .bazelversion or USE_BAZEL_VERSION names, and checks the download against a checksum from the same release site. Pinned versions are old, so the exposure is an agent choosing a just-released Bazel.

When a cooldown blocks a build: in both npm and Bazel, the error looks exactly like the error for a version that does not exist. tools/cooldown/explain_failure.sh uses registry metadata to tell the two cases apart. Under RUNBOOK section 2, the outer agent escalates a block to the operator, and an agent never loosens the cooldown.

Cost to experiment fidelity

  • Agents pick versions the snapshot lacks. Two early runs chose "latest" versions by curl-ing bcr.bazel.build/modules/<m>/metadata.json directly. Under the snapshot, a version from the last 7 days won't resolve, and the agent must fall back. Expect some extra iterations; count them in RESULTS (environment_deviations).
  • Projects with fresh pins fail to resolve. A project whose own MODULE.bazel pins a very fresh version will not resolve. A CMake project chosen as a target normally has no Bazel files, so this should be rare.

2. Host resources (in place)

  • Disk floor: preflight refuses to launch below 100 GB free (A2B_MIN_FREE_GB). For scale, in the first lab 4 runs grew ~/.cache/bazel to 7.9 GB, and lab-holding to 3.8 GB.
  • Per-run caps and accounting. Every generated launch.sh runs the inner agent through tools/run_capped.sh, in its own cgroup scope. Defaults are 24G memory, 4G swap, 16 cores, and 8,192 tasks, overridable per run via A2B_MEM_MAX, A2B_SWAP_MAX, A2B_CPU_QUOTA, and A2B_TASKS_MAX. With A2B_CAPS=width1, a run that is alone in the slice gets the whole slice. Large targets run at width 1, by the first lab's ruling, because a cap that exists only to share the machine shouldn't fail them.
    • What it records: run/resources.tsv is a time series, sampled every 5 s, of the run's memory, swap, cpu, and pids, plus machine-wide available memory, load, disk I/O, and free disk. run/resources.json holds exact kernel peaks: memory.peak, pids.peak, cpu.stat including throttling, and memory.events including oom_kill. Both files also hold pressure stall (PSI) for cpu, memory, and io. PSI is the share of the run's wall time that its tasks spent waiting for each resource, which is the direct measure of a bottleneck.
    • Leftovers: processes still alive when the agent exits, such as Bazel servers, are recorded and then terminated.
    • Checked with controls: keeping 4 cores busy for 4 s gave cpu_usage_s 16.0. A 600 MB allocation under MemoryMax=200M gave oom_kill: 1 and a peak at the cap, and an uncapped 300 MB allocation gave a 319 MB peak. Under CPUQuota=100%, 4 busy cores averaged 0.98 cores, with 12 s throttled and a cpu PSI of 65% (throttling counts as CPU stall). A 300 MB working set under MemoryMax=100M with swap gave a memory PSI of 50%. An idle sleep gave 0% on all three resources. A setsid daemon was recorded and terminated. Exit code 7 was propagated.
    • Two settings the controls forced: the first is OOMPolicy=continue, because systemd's default tears down the whole scope on an OOM kill, taking the peak counters with it. The second is polling for completion every 0.5 s, because wall_s was otherwise inflated by up to one sample interval.
  • All runs together: a systemd slice, a2b.slice, caps all the runs combined. tools/caps/install_slice.sh writes it to ~/.config/systemd/user/ from the A2B_SLICE_... settings. The first lab's machine (32 cores, 91 GiB) ended on 80G memory, 8G swap, 28 cores, and 32,768 tasks, after a first study at 64G. That left about 11 GiB and 4 cores for everything that is not a run. The non-reclaimable use of everything that is not a run measured 8–9 GiB. The backstop is the wave sampler's host-safety abort, which fires when MemAvailable is below 2 GiB for 60 s.
  • Disk I/O is recorded machine-wide only, because the io controller is not delegated to user cgroups.
  • Shared memory: each container gets an 8 GB /dev/shm (a2b-run-env --shm-size=8g), not podman's 64 MB default. It is tmpfs, so its pages count against the run's memory cap like any other pages. yugabyte-db's parallel test suite needed the larger size: 153 tests failed on the default.

3. Runner user (in use)

Inner agents run as runner, an unprivileged user that has:

  • no SSH key, no gh token, no sudo, and a locked password
  • its own Claude login, on the account the operator chooses (the last section)
  • pinned copies of claude and node in /srv/a2b

The operator's home is drwxr-x---, so the runner cannot read the lab, lab-holding, or any credential in that home. Setup, upkeep, and a complete undo are in tools/runner/README.md. tools/runner/check_runner.sh verifies every property with negative controls.

⚠ Rule: every runner command goes through tools/runner/as_runner.sh <dir> -- <cmd>, never a bare sudo -u runner. An inherited working directory bypasses the 0750 home: sudo -u runner keeps the caller's cwd, and relative lookups don't re-check the cwd's parents. When a command was launched that way from the lab's own directory, the runner could ls ., read SECURITY.md and a run's stdout.txt, and list ../any2bazel, the skill source. Seeing the skill source would contaminate a no-skill arm. (Credentials stayed unreachable, since ../.. is the 0750 home.) The wrapper does cd / before sudo, a clean env -i, and then cd <dir> as runner, and it fails if the second change of directory doesn't work. check_runner.sh uses the wrapper and verifies it: a process launched through the wrapper from inside the lab starts in /home/runner. A paired control shows that raw sudo from the lab still leaks, so the test can tell the difference.

Optional defense in depth (the operator's call): chmod -R o-rwx on the directory holding your clones of the lab and the skill would close the hole even if some future command skipped the wrapper. It costs nothing unless another local user needs those files. But new directories get o+rx again under the default umask 002.

Design choices, and their costs:

choice protects against cost
launch via sudo -u runner env -i …, which a sudoers rule allows: the owner may act as runner only credential reach; env leakage (tokens in the owner's environment) anything running as the owner, including the outer agent, can act as runner. This is acceptable, because the runner is strictly less privileged
workspace root 3710 (traverse, no list) concurrent runs seeing each other's workspaces none, since each run is handed its own path
cooldown configs root-owned in /srv/a2b/runner-config, symlinked the agent editing its own user-level cooldown a project .npmrc or a command-line --registry can still override it (section 1, "Gaps")
claude copied, not linked reading the owner's home; silent auto-update mid-batch re-sync to change versions (recorded in /srv/a2b/VERSIONS)
runner's own Bazel caches reading the owner's output bases (two early runs' migrations) cold first build
cgroup caps still apply host starvation none: sudo's PAM stack keeps children in the caller's scope (checked by check_runner.sh)

What an end-to-end test of the launcher showed. Before any real run, the first lab took one run through every step (launch, collection, bundle, holding) with a stand-in for claude that tried to break the isolation. It then did the same once with a real claude -p. The test showed five things:

  • The agent starts where it should. It received exactly the arguments the launcher gave it, and it ran as runner, in the run's workspace, with the run's private TMPDIR.
  • The isolation held. The stand-in tried to read the lab, to read the owner's SSH key, to list the directories that hold all runs' workspaces and temp directories, and to find a token in its environment. Every attempt was denied.
  • A session's files are where the tools look for them. The transcript is written under ~runner/.claude/projects/<slug>/. Claude Code's temp root is in the run's private TMPDIR (/home/runner/t/NNN/claude-<uid>/…), not in the shared /tmp. collect_run.sh finds both.
  • A launch is refused when another run could leak into it. That is the case while a finished run's leftovers are present (until to_holding.sh is run), and while a run on the same target is live. A live run on a different target is allowed, with a note.
  • A bundle is the same wherever it is made. make_bundle.sh produced the same tree from the live workspace, which the runner owns, and from the copy in holding. The stand-in's migration added one file and deleted one, so the comparison covered a deletion as well as an addition.

The same test found two defects before any real run, and each is now a check. The installed skill directory was mode 0700 (from mktemp -d), so a skill arm would silently have had no skill. Preflight now checks that the directory is readable as runner. run_capped.sh recorded the runner's leftover processes but couldn't kill them, because the owner can't signal them. It now sends TERM as the user that owns each process, with cgroup.kill as a backstop.

Residual exposure:

  • Visible session names: concurrent runs can see each other's session-dir names in ~runner/.claude/projects (not the workspaces), so they know which runs exist. A concurrent run on the same target is refused.
  • Caches: each run has its own cold cache in its private temp dir (XDG_CACHE_HOME=/home/runner/t/NNN/cache, set by as_runner.sh for any command in the run's space), so runs share no Bazel output base, repository cache, or Bazelisk download. The Bazel binary is seeded from the owner's copy after a hash check against the release checksum, never from the runner's writable ~/.cache. to_holding.sh records the cache's size and deletes it.
  • /tmp: agents write to /tmp despite a private TMPDIR (six early runs did, into the host's). So each agent gets a /tmp of its own. For a run in a build environment, it is the container's. Otherwise a2b-private-tmp bind-mounts the run's /home/runner/t/NNN/tmp over /tmp in unprivileged user and mount namespaces, keeping the runner's uid. The host /tmp is still checked for runner leftovers before launch (clear_runner_tmp.sh), because verification uses it.
  • What the runner can reach, an injection can reach: the network, and the runner's own Claude session and login (the last section).

Passing a script into a container

Rule. A lab tool hands a script to a container as one already-built word (bash -c "$VAR"), as a single-quoted literal, or through bash -s with a single-quoted heredoc and positional arguments. It never interpolates a script into a bash -c "…" string. And a script that must run inside a container proves that it does: it asserts id -u == 0 and exits 3 otherwise. So the log shows whether the script ran in a container, and containment does not rest on what the launcher intended.

Why. tools/env/validate_target_image.sh once passed its inner script as an interpolated bash -c "…". A comment containing a double quote closed the string early, so only the clone ran in the container. cmake -S src -B build, cmake --build and ctest for FreeCAD, QGIS, CMake and openttd then ran on the host as the owner, outside the image, against the host's installed packages. These host builds went on for about 13 hours, and were identified only afterwards, by the owner-owned files they left on the host (/tmp/build.log, /tmp/ctest.log, build/ trees under /home/runner/t/imgcheck-*).

All four are well-known public projects at pinned commits and nothing anomalous was observed, but the isolation the design promises was absent for those invocations. No run was contaminated: every launcher, prepare_reference.sh, verify_run.sh and scaffold.sh already used one of the safe forms, and the breach was confined to image validation before any run. The guard is proven in both directions: run on the host as the owner, the guarded script refuses, and run in the container, it returns 0.

The account's claude.ai connectors are switched off for inner agents

What the tools do. A connector links a claude.ai account to an outside service, such as Google Drive, and gives an agent tools that act on it. tools/new_run.sh adds ENABLE_CLAUDEAI_MCP_SERVERS=false to every agent's environment, in both arms, and refuses a --claude-env that sets it to anything else (tools/tests/test_new_run_connectors.sh). This is the client's own switch: a probe with the pinned client as runner loaded four connectors without the switch and none with it. collect_run.sh then fails a run whose transcript carries any claude.ai MCP server or mcp__claude_ai_ tool, so every run proves that the switch worked, and the lab does not assume it.

Why. Inner agents run on a claude.ai account login, and Claude Code loads that account's connectors automatically. In the first lab, which used the operator's own account, the sessions of 29 runs carried a connected Claude Docs connector with create/update/delete tools. The tools were deferred but loadable, and the sessions were launched with --dangerously-skip-permissions. An inner agent could have written into or deleted the account owner's claude.ai documents without any prompt. None did: none of the first lab's 67 transcripts shows a call to a connector tool. (The account's Gmail, Google Calendar and Google Drive connectors were listed too, in state needs-auth, so they were not usable.) A transcript holds connector names and states, not credentials.

The runner's shared home, and what a container sees

What the tools do.

  • Per-run directories: as_runner.sh points XDG_CONFIG_HOME, XDG_DATA_HOME and XDG_STATE_HOME into each run's own temp dir, as it does XDG_CACHE_HOME. For a reference store, it points them into that store's own directory.
  • A baseline for the rest: some programs ignore those variables and write to the runner's home anyway. tools/runner/runner_home.sh catches what they write, by comparing the home with a recorded baseline. to_holding.sh archives those files with the run, and check_containment.sh refuses a launch until the home is back at its baseline.
  • A narrow mount: of /srv/a2b, containers see only bin, node, bcr-snapshot, runner-config and VERSIONS. They do not see podman's image storage. That storage holds every finished run's committed container, and so it holds whatever each run's agent left in its own /tmp.
  • ⚠ Never bypass as_runner.sh. The first lab's outer agent ran a bare sudo -u runner podman ps. The command skipped the per-run directories, so it wrote podman state into the runner's home.

The pinned Claude Code keeps its credentials and transcripts in ~/.claude, which the per-run directories do not affect. What the tools do is proven by tools/tests/test_as_runner_xdg.sh, test_runner_home.sh and test_containment_runner_home.sh, each with controls.

Why. Every run, reference build and verification runs as runner, and every container mounts /home/runner read-write. For as long as only the Bazel and download caches were per run, whatever a test suite or an agent wrote to ~/.config, ~/.local/share or ~ itself stayed there for the next run, including the second arm of a pair. In the first lab these leftovers had reached 7.6 GB when they were found: QGIS, FreeCAD and openttd settings, ~/.bitcoin, a buildifier in ~/bin from a pilot run, and one run's 6.3 GB Bazel output base. No run was affected, as far as the transcripts can show. Four later runs looked for buildifier and did not find it (~/bin is not on the agent shell's PATH). No agent read the output base or an image layer, although three agents' find / listed layer files. Whether a test program silently read stale settings cannot be seen in a transcript.

Not solved: concurrent runs. Two runs live at once still share one home. This must be solved before any bin-packing, that is, before several runs are scheduled side by side to fill the machine (the first lab's operator's ruling).

The runner's Claude credentials: a decision for every operator

Every operator decides this for their own lab, before the runner's first login and before any run is launched: which Claude account the inner agents run on, knowing that every inner agent can read that account's login. The outer agent records the decision in the study's pre-registration (CLAUDE.md, "What only the operator can do").

The exposure. /home/runner/.claude/.credentials.json holds an OAuth access token and refresh token for the account the runner is logged in to. Every inner agent runs as runner, with Claude Code's permission prompts bypassed, with network access, and with /home/runner mounted read-write. So any inner agent can read these credentials. Inner agents also read far more untrusted text than anything else on the machine: upstream AGENTS.md/CLAUDE.md files, build scripts, downloaded content. Untrusted text is where a prompt injection would come from. A review of the first lab ranked this exposure as that lab's most consequential security item. Nothing detects such a read: collect_run.sh does not flag a transcript command that touches .credentials.json.

The alternatives, and what they cost. The alternatives that narrow the credential's scope are a separate account for the runner's login, or an API key with a spending cap. Either one takes the inner agents' work off the operator's own subscription. The first lab's operator judged that this would raise the cost of the work substantially. An API key also needs a change to the launcher. The launcher passes none of the operator's environment to the runner, so the runner's login is the only way the lab gives an inner agent credentials.

What the first lab decided: it accepted the exposure, on the operator's own account. The operator's words: "the benefit of having inner agent work 'charged' to my subscription is high enough that I'm comfortable continuing with this risk." For comparison, the outer agent runs as the owner and has strictly more reach than an inner agent: the same account's credentials, the owner's whole home and the git remote. An inner agent does not have more privilege than the outer agent. It has more exposure to untrusted text.

There aren't any published security advisories