Skip to content

25. Two sandboxes sharing one directory (scratch pads)

25. Two sandboxes sharing one directory (scratch pads)

Learning goal: whether jobs in separate gVisor sandboxes can share a host directory the way processes on one machine share a disk, which is what named scratch pads need (Gavin, 2026-11-25: pads shared between concurrent jobs are the job creator's choice, "the same thing that happens on a normal system"). Two things decide it: whether one sandbox sees another's writes promptly, and whether file locks taken in one sandbox block the other. cargo (its registry and target/) and uv (its cache) rely on flock() to stay consistent under concurrent use; if locks don't cross sandboxes, two jobs on one pad can corrupt it even though both tools are written to cope.

Method: spike/cri_shared_mount.py on smaug (gVisor release-20261116.0, runsc with no runsc.toml, so its defaults), as the developer set up by deploy/linux/dev-host.sh. Two CRI pods, each its own sandbox, mount one fresh host directory at /pad and run as the developer's uid. A takes an exclusive flock() and lockf(); B tries both without blocking, and also a flock() the host holds; A then rewrites a file B has already read, and B times how long until it reads the new content; finally B takes the flock() blocking while A still holds it. runc is the baseline, where everything is one kernel.

Predictions:

Question runsc runc
A new file from one sandbox seen by the other within 0.1 s at once
A rewritten file's new content seen by the other within 1 s (bind mounts are revalidated against the host by default, unconfirmed) at once
B's flock() while A holds it acquired: locks live in each sandbox's kernel, not the host's (unconfirmed) blocked
B's lockf() while A holds it acquired, as flock() blocked
B's flock() while the host holds it acquired blocked
B's blocking flock() returns at once waits ~8 s for A's release

Raw results

One run per handler, 2026-11-25, both probes exit 0. Times are from one sandbox's event to the other's.

Question runsc runc
A new file from one sandbox seen by the other 0.0 s (B saw a-ready on its first look); A saw b-ready 0.135 s after starting to poll 0.0 s; 0.192 s
A rewritten file's new content seen by the other 0.003 s 0.004 s
B's flock() while A holds it acquired blocked (EAGAIN)
B's lockf() while A holds it acquired blocked
B's flock() while the host holds it acquired blocked
B's blocking flock() returned at once waited 7.996 s, until A released

runsc flags on smaug has no option about file locks. --file-access-mounts defaults to shared ("filesystem validation" for mounts other than the root), which fits the prompt reads.

What we learned

  • Files cross between sandboxes as on one machine. A write in one is readable in the other within milliseconds, new files and rewrites alike.
  • File locks do not cross sandboxes, or reach the host. gVisor keeps flock() and POSIX locks inside each sandbox's own kernel: two jobs each get an exclusive lock on the same file at the same time, silently. The predictions held throughout.

What it changes

  • Two jobs using one pad at once are less safe than two processes on one machine: cargo and uv lock their caches and target/ against concurrent use, and under gVisor those locks protect nothing between jobs. Anything that relies on locking (cargo's build directory, uv's cache, git's index.lock) can be corrupted by concurrent writers, with no error.
  • So if the runner should give pads the safety a normal machine gives, it has to coordinate writers itself; the sandboxes can't.