👨‍🍳 TokenChef (Part 05)

Honest Inputs, Silent Sandboxes


GitHub Repository: zywkloo/wteval Reproducible Seatbelt Probe Script Red-Team Evidence Table

Contents


1. A cache is a promise (and Bazel’s sandbox isn’t security)

A build cache promises: same declared inputs → same output. Two things break that promise without raising an error: action non-determinism (timestamps, random seeds, locale) and undeclared inputs (reading host headers, $HOME, or ambient tools that were never hashed). Locally that yields a stale artifact; in a shared remote cache, one dishonest action poisons builds for every developer on the team (Bazel Sandboxing, Bazel Hermeticity).

Flowchart showing how declared inputs form a cache key while undeclared inputs or drift silently produce stale or poisoned cache hits

Bazel’s sandbox exists to keep that cache key honest and match remote execution—not to provide security or confidentiality. Bazel’s own documentation states this plainly: “Sandboxing doesn’t hide the host environment in any way. Processes can freely access all files on the file system.” On macOS, Bazel’s darwin-sandbox starts with (allow default) and leaves reads open unless you explicitly pass --sandbox_block_path.

2. Who pays for strictness—and what tools actually isolate

Strict input enforcement costs build engineers, rule maintenance, and developer friction. One stylized way to think about the payoff is a toy model: if per-build time saved over native tooling is Δ(N) for N engineers, then total daily savings scale as N × builds/day × Δ(N) while platform cost scales closer to F + τ·N. Under the assumption that Δ(N) grows linearly with repo coupling (≈ N), benefit scales as N² against linear cost N and eventually crosses over.

That N² curve is an assumption, not an empirical law, and three realities routinely flatten it: modern native and mid-tier tools already ship incremental builds and shared remote caches that eat most of Δ; modular repos and polyrepos bound the subgraph any single engineer touches so Δ(N) plateaus; and migrating fast-moving ecosystems imposes step-function rule costs rather than a smooth tax τ·N. Public evidence for strict builds paying off comes mainly from large, tightly coupled monorepos paired with remote execution—for example, Buck2 reports 2–4× faster CI and user-populated caches via sandboxed remote execution (Buck2 Compared to Buck1).

Across real build tools, “isolation” means very different things—and local OS sandboxing is much rarer than folklore suggests:

ToolInput hashingLocal isolationRemote cache / RE
GradleTask inputs (@InputFiles, properties, classpath)None (host workspace); missing inputs cause bad hitsShared HTTP cache; docs advise only clean CI writes
TurborepoFiles + declared env / globalEnv (Caching)Strict Env Mode strips undeclared env vars (v2+); no OS FS sandboxTeam remote cache; missing env vars still fail silently if app falls back
NxDeclared file, env, and runtime inputsOpen-source local Nx has no OS FS sandbox; Nx Cloud Ultracache traces file reads on Workers (Remote Cache)Local + Nx Replay remote cache (tracing observes, does not block)
PantsContent-addressed digests + dep inferenceEphemeral per-process TempDir with declared inputs (local.rs); no namespaces or Seatbelt locallyOptional docker_environment (Environments) or REAPI
Buck2Action digest (command + inputs) via DICERuns directly in checkout / buck-out (local.rs); --isolation-dir isolates daemon state, not FS reads (Isolation Dir)RE-first: sandboxing lives on RE workers so all users write to cache
BazelAction digest (command, env, inputs, toolchains)processwrapper (symlinked execroot); linux-sandbox (namespaces, RO host FS, opt-in --experimental_use_hermetic_linux_sandbox); darwin-sandbox (sandbox-exec: writes restricted, reads open)Remote cache + REAPI; local sandboxing acts as a parity check for RE

3. An evaluation score relies on the same invariant

I ran into the same input-honesty invariant while building wteval to evaluate coding agents (agent-isolation.md). In a build system, the key is the hash of declared inputs and the artifact is the output. In an agent evaluation, the experimental condition is the key and the score is the output:

Build systemCoding-agent evaluation
Cache key (declared inputs)Task statement + workspace at base commit + agent config
Cached outputThe evaluation score (pass/fail verdict)
Undeclared inputReference fix, later git commits, prior runs, other sessions’ transcripts
Dishonest resultAn unearned pass attributed to the base prompt
Symptom in the logNone. The record looks completely clean.

The agent does not have to be adversarial for this to happen, only resourceful. When a task is hard, it searches—and a search that wanders outside the workspace silently invalidates the measurement.

4. Absence vs. Prohibition (and why neither guarantees a loud error)

There are two structural ways to keep an undeclared input out of a process: absence (the file does not exist in the filesystem view the process can see) and prohibition (the file is on disk, and an OS policy denies access).

It is tempting to say “absence fails loudly with ENOENT, whereas prohibition fails silently.” That is false for missing required inputs. In a build system, a symlinked execroot still fails silently whenever tools have lookup fallbacks: shells fall back to PATH (/usr/bin), C/C++ compilers fall back to /usr/include or host SDKs, interpreters fall back to sys.path, optional configs fall back to defaults, and Bazel’s darwin-sandbox leaves absolute host paths readable.

Absence’s real advantage shows up when withholding forbidden inputs (secrets or evaluation answers): a file that literally does not exist in a container, VM, or mount namespace cannot be read, even if the process ignores ENOENT. Prohibition leaves the answer sitting on disk and bets everything on a deny rule matching the kernel’s path:

DimensionAbsence (VM / container)Prohibition (host Seatbelt)
MechanismFile is never mounted in process viewFile is on disk; policy denies it
Build analogyRE worker; hermetic Linux sandboxBazel --sandbox_block_path on macOS
Agent-eval analogyEphemeral VM/container, base commit onlyOuter sandbox-exec on workstation
Missing required inputStill falls back (PATH, /usr/include)Same
Withheld forbidden inputCannot be read (not mounted)Rule mismatch → silent allow

Two-panel diagram comparing Absence where a withheld secret is not mounted versus Prohibition where a mismatched Seatbelt deny rule falls through silently to allow default

A local coding agent needs a home directory, provider authentication, and host toolchains, so on a macOS workstation we started with prohibition. That put the entire isolation guarantee on the bottom-right box.

5. Shaping the agent’s profile through failing probes

We tested the agent CLI’s built-in isolation options first, because they are the obvious answer (agent-isolation.md):

LayerWhat the probe showed
The agent CLI’s sandbox flagRestricted the shell tool only; the built-in file tool still read home directories
The agent CLI’s workspace-only settingNo effect in print mode
Outer Seatbelt profile around full argvKernel-enforced, inherited by every child; held for both shell and file tool (inner sandbox disabled because nested sandbox_apply fails)

Every rule in the outer profile was then forced by a probe that came back wrong:

Probe came back wrongFix
Keychain query answered errSecItemNotFound (keychain reachable)Deny ~/Library/Keychains and securityd mach services (errSecParam)
Keychain CLI binary still executed despite a read denialdeny process-exec (literal "/usr/bin/security"), not just file-read*
Agent read its own CLI store holding 127 prior conversationsGenerate profile per run: deny every conversation artifact present at launch
A sibling IDE agent’s store held orchestrator transcriptsEnumerate every agent front end installed on the machine
Agent listed the run’s parent directorydeny file-read-data (literal <dir>); verified on macOS 27.0.1 that file-read-metadata and file-read* break git init (rc=128)
Profile copied from another machine denied nothingRender paths on the host machine and verify every rule path exists

On macOS, /tmp, /var, and /etc are symlinks into /private, users create symlinks mid-path, and APFS firmlinks expose /private under /System/Volumes/Data/private (/usr/share/firmlinks). Seatbelt matches (deny …) rules only against the kernel’s canonical path:

Diagram of macOS Seatbelt path canonicalization showing /tmp symlinks and /System/Volumes/Data firmlinks resolving to /private/tmp before rule evaluation

Measured on macOS 27.0.1 (build 26A434, 2026-11-30) via scripts/probe_seatbelt_symlinks.sh using one-rule (allow default) profiles. First, path resolution across symlinks and APFS firmlinks:

CategoryDeny rule (file-read*)Access testedResult
/tmp symlinksubpath "/tmp/…/blocked" (pre- or post-mkdir)/bin/cat via /tmp/… or /private/tmp/…ALLOWED — ignored
/tmp resolvedsubpath "/private/tmp/…/blocked"/bin/cat via /tmp/… or /private/tmp/…DENIED
/var/tmp symlinksubpath "/var/tmp/…/blocked"/bin/cat via /var/tmp/… or /private/var/tmp/…ALLOWED — ignored
/var/tmp resolvedsubpath "/private/var/tmp/…/blocked"/bin/cat via /var/tmp/… or /private/var/tmp/…DENIED
/etc symlinkliteral "/etc/hosts" vs "/private/etc/hosts"/bin/cat /etc/hosts/etc ALLOWED; /private/etc DENIED
Mid-path symlinksubpath "…/mid_link/sub" (abs or rel)/bin/cat via link or real_dirALLOWED for both
Symlink nodesubpath "…/mid_link"/bin/cat via link vs real_dirLink DENIED; real_dir ALLOWED
Resolved targetsubpath "…/real_dir/sub"/bin/cat via link or real_dirDENIED for both
APFS firmlinksubpath "/private/tmp/…/blocked"/bin/cat /System/Volumes/Data/private/tmp/…DENIED (no bypass)
APFS firmlink rulesubpath "/System/Volumes/Data/private/tmp/…"/bin/cat via /private/tmp/… or /System/Volumes/Data/…ALLOWED — ignored (realpath keeps prefix)

Second, Python operations (open, os.stat, os.listdir), rule scopes, and (debug deny) unified logs:

ProbeRuleResult
Python (open, stat, listdir)file-read*, file-read-metadata, or file-read-data on /tmp/…ALLOWED across all 3 ops and all 3 rules
Python (open, stat, listdir)file-read-metadata on /private/tmp/…stat DENIED; open & listdir ALLOWED
Python (open, stat, listdir)file-read-data on /private/tmp/…open & listdir DENIED; stat ALLOWED
(debug deny) + log showIgnored /tmp/… rule (sender=="Sandbox")ALLOWED, stderr none, 0 log entries
(debug deny) + log showMatched /private/tmp/… rule (sender=="Sandbox")DENIED (EPERM), logged (deny(1) file-read-data /private/tmp/…)

Two subtle takeaways came directly out of expanding these probes. First, realpath alone is not enough on APFS macOS: os.path.realpath("/System/Volumes/Data/private/tmp/…") preserves /System/Volumes/Data because firmlinks are not symlinks, yet Seatbelt silently ignores any rule carrying that prefix. Second, (debug deny) and macOS Unified Logging only catch rules that fire: actual denials appear under sender=="Sandbox", whereas an unmatched rule falls through to (allow default) with zero stderr warnings and zero log lines.

Five-step Seatbelt profile render pipeline: deny list, realpath, strip /System/Volumes/Data firmlink prefix, existence check reporting missing paths, and pre-run denial probe

7. Checking Bazel’s darwin-sandbox in source and live

Reading Bazel master at 24c5dcf (DarwinSandboxedSpawnRunner.java, SandboxOptions.java, FileSystem.java, UnixFileSystem.java, unix_jni.cc) and running Bazel 9.3.3 with --spawn_strategy=darwin-sandbox --sandbox_debug shows how Bazel handles the same macOS Seatbelt semantics (seatbelt-symlink-probe.md):

DimensionBazel darwin-sandboxAgent-eval profile (make_base_profile.py)
Base policy(allow default) + (debug deny)(allow default)
Writes(deny file-write*), then allowlist (/dev, /private/tmp, /private/var/tmp, execroot, Caches)Allowed except enumerated deny list
ReadsUnrestricted unless --sandbox_block_pathDenied for enumerated list (per-run)
Other rules(allow process-exec (with no-sandbox) (literal "/bin/ps"))deny process-exec (keychain CLI), deny mach-lookup (securityd)
NetworkAllowed by default (--sandbox_default_allow_network=true, SandboxOptions.java:292); when off, network-inbound remote filter “compiles but has no effect” (DarwinSandboxedSpawnRunner.java:287–294)Not blocked for the agent
Path handlingresolveSymbolicLinks(); spells /private/tmp, /private/var/tmprealpath; reports missing paths

Bazel resolves symlinks before rendering sandbox.sb, with one fallback path in SandboxOptions.getInaccessiblePaths: when blockedPath.resolveSymbolicLinks() throws IOException, Bazel catches it and adds the raw blockedPath. Tracing FileSystem.resolveSymbolicLinks (FileSystem.java:485–493) → appendSegment (FileSystem.java:417–446) → UnixFileSystem.resolveOneLink (UnixFileSystem.java:72–85) → JNI NativePosixFiles_readlink confirms what happens on macOS: readlink(2) returns EINVAL for non-symlinks (handled as nullptr), but returns ENOENT for missing paths, throwing FileNotFoundException (IOException). Catching it discards the already-resolved /private/tmp prefix—whereas Python’s os.path.realpath resolves existing parent prefixes even when the leaf is missing.

Running a minimal genrule workspace on Bazel 9.3.3 (--spawn_strategy=darwin-sandbox --sandbox_debug) verified all four cases:

Bazel flagRule emitted in sandbox.sbAction result
(none — default)(no deny file-read*, no deny network*)Read /tmp/…/existing_dir/secret.txt succeeded
--sandbox_block_path=/tmp/…/existing_dir(subpath "/private/tmp/…/existing_dir")Read DENIED
--sandbox_block_path=/tmp/…/missing_dir(subpath "/tmp/…/missing_dir")Action created dir (/private/tmp writable) and read it: succeeded
--sandbox_block_path=/tmp/…/dangling_link(subpath "/tmp/…/dangling_link")readlink succeeded; after target creation, read succeeded

Excerpt of the actual sandbox.sb captured from Bazel 9.3.3 for the missing-path run (user home/temp paths redacted):

(version 1)
(debug deny)
(allow default)
(allow process-exec (with no-sandbox) (literal "/bin/ps"))
(deny file-write*)
(allow file-write*
    (subpath "/dev")
    (subpath "<HOME>/Library/Caches")
    (subpath "<DARWIN_USER_TEMP_DIR>")
    (subpath "/private/var/tmp")
    (subpath "<HOME>/Library/Developer")
    (subpath "<HOME>/Library/Logs")
    (subpath "/private/tmp/.../execroot/_main")
    (subpath "/private/tmp")
    (subpath "<DARWIN_USER_CACHE_DIR>")
    (literal "/private/tmp/.../stats.out")
)
(deny file-read*
    (subpath "/tmp/.../missing_dir")
)

Scope matters here: for pre-existing host directories (the normal use case of --sandbox_block_path, such as blocking /opt/homebrew or /usr/local), Bazel resolves symlinks cleanly and blocks reads as designed. The fallback fails open only in two narrow cases: a blocked path under a symlinked prefix (/tmp, /var) that does not exist when the action starts and appears before read, or a pre-existing dangling symlink under /tmp or /var—where even readlink succeeds despite SandboxOptions.java:226–227 explicitly assuming the symlink itself will remain blocked.

8. What the sandbox still doesn’t cover

GapCurrent mitigation
Network: a single curl fetched a public reference file under an otherwise working profilePrivate target repo whose reference is not on the public internet (a property of the task set, not the sandbox)
Scoring executes agent-edited code on the hostSeparate workspace, evaluator’s own tests, deny-network profile
The agent CLI’s own auth token stays readableRequired to authenticate to the provider; accepted
A deny list covers only what someone enumeratedRe-probe after every CLI upgrade
sandbox-exec is deprecated by Apple (SANDBOX-EXEC(1))Accepted for host wrappers; moving to true Absence requires a Linux VM or container boundary

9. Checklist

DoBecause
Resolve every rule path with realpath and strip /System/Volumes/DataUnresolved symlinks and APFS firmlink prefixes silently match nothing
Report rule paths that don’t exist at render timeA missing path can leave a dead rule or trigger a raw-path fallback
Probe the expected denial, not only task successUnder (allow default), a passing run proves nothing about isolation
Do not expect (debug deny) logs to flag dead rulesUnified Logging records matched denials, never unmatched rules that fall through
Probe both the shell and the agent’s built-in file toolOne has held while the other leaked
Record rendered profile text + SHA-256 hash in provenanceUnreconstructable isolation is not audit evidence
Re-probe after OS, profile, runner, or agent CLI upgradesEach of those four has silently broken isolation

Reproduce

The self-contained probe script is pinned at scripts/probe_seatbelt_symlinks.sh (full recorded results and Bazel 9.3.3 notes in docs/seatbelt-symlink-probe.md, red-team evidence table in docs/drafts/honest-inputs-review.md).

Run it directly on macOS (no sudo, ~3 seconds, cleans up its temporary directories under /tmp and /var/tmp on exit):

curl -fsSL https://raw.githubusercontent.com/zywkloo/wteval/2a2effb8361771ade6ae52afa2eb71a02194c864/scripts/probe_seatbelt_symlinks.sh | bash
🔗Citation (BibTeX)
@misc{zhang2026honestinputssilent,
  title        = {{Honest Inputs, Silent Sandboxes}},
  author       = {Victor Zhang},
  year         = {2026},
  month        = nov,
  howpublished = {\url{https://zywkloo.github.io/blog/honest-inputs-silent-sandboxes/}},
  url          = {https://zywkloo.github.io/blog/honest-inputs-silent-sandboxes/},
}