feat(check): support copy-on-write sandboxing on Linux#156
Merged
Conversation
`select_sandbox()` gated the real CoW sandbox to macOS and routed every other target — including Linux — to `UnsupportedSandbox`, which always errored. `multi check` therefore could not create a sandbox on Linux at all. Add a native Linux implementation, `ReflinkSandbox`. Linux has no whole-tree clone syscall like macOS's `clonefile`, so it recreates the directory structure under a temp dir and clones each regular file with the `FICLONE` ioctl (a reflink — a metadata-only, copy-on-write share of the file's extents). `FICLONE` only works on CoW filesystems (Btrfs, XFS with reflink=1, bcachefs); on others (ext4, tmpfs) it fails and we fall back to a plain byte copy, so the sandbox is always an independent clone — just without the CoW space savings. Permissions (incl. exec bits) are preserved on both paths, and symlinks are recreated verbatim. Wire it into the `cfg` selection (macOS → clonefile, Linux → reflink, other → stub) and widen the independence test to run on Linux too. Update CHECKS.md to require sandboxing on both macOS and Linux. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
8211a8b to
6b1ee8b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
select_sandbox()gated the real copy-on-write sandbox totarget_os = "macos"and routed everything else — including Linux — toUnsupportedSandbox, which always errors. Somulti checkcould not create a sandbox on Linux at all; every run failed before an agent could start.Fix
A native Linux CoW sandbox,
ReflinkSandbox(src/checks/sandbox/linux.rs):clonefile(2), so it walks the tree, recreates directories/symlinks, and clones each regular file with theFICLONEioctl — a reflink (metadata-only, copy-on-write share of the file's extents).FICLONEonly works on CoW filesystems (Btrfs, XFSreflink=1, bcachefs). On ext4/tmpfs/overlay it fails, so we fall back to a plain byte copy — the sandbox is always a fully independent clone, just without the space savings.Wiring (
src/checks/sandbox/mod.rs):cfgselection is now macOS →clonefile, Linux → reflink, any other target → the erroring stub. The independence test now runs on Linux too.CHECKS.md: the sandbox requirement is now Cross-Platform and Platform-Gated — it fails if a real sandbox is created on only one of macOS/Linux.Validation
cargo make clippy+cargo make test(119 pass).macos.rsis not built): compiled the exact reflink logic in a Linux container — clippy-clean; fallback copy path verified on overlay fs;FICLONEsuccess path verified on a real btrfs loopback (reflink OKper file). Independence, nested dirs, symlink preservation, exec-bit preservation, and RAII teardown all pass on both paths.Note
Reflinks only engage when
$TMPDIRand the working tree share the same CoW filesystem (same cross-volume constraint macOSclonefilehas). Otherwise every file takes the correct-but-not-CoW copy fallback. A future tweak — placing the temp dir as a sibling of the source tree — would guarantee reflinks; left out of this PR to keep parity with the macOS implementation.🤖 Generated with Claude Code