Hermetic builds ensure reproducibility and isolation: given the same inputs (source code, dependencies, tools), you always get the exact same output artifact, regardless of when/where you build. This eliminates "it works on my machine" issues. Systems like Bazel, Buck, or Pants excel here.
Cache correctness is the backbone: remote/action caches must be sound (no false hits) and complete (maximizes valid hits). Failures lead to rebuilds (slow) or incorrect outputs (disastrous).
Below, I break it down by your topics: hashing, sandboxing, poisoning defenses, and metrics.
1. Hashing for Determinism and Content-Addressing
Hashing turns inputs into unique, collision-resistant keys for caches.
Input hashing:
Action key: Hash of everything affecting an action: command line, inputs (files + metadata like mtime/size), environment vars, execution root.
Skykey (Bazel term): Merkle tree hash over deps + action graph for remote caching.
Use stable hashes like SHA-256. Avoid mtime (non-deterministic); use content hashes.
Output hashing:
Content-addressable storage (CAS): Artifacts stored/retrieved by hash of content (e.g., blake3(file contents)). Remote Execution (REAPI) mandates this.
Validates integrity: If hash mismatches, reject/poison.
Cache lookup flow:
code
Compute action key (hash(inputs + env + cmd))
↓
Query remote cache: "Give me output for key X"
↓
Fetch & verify output hash matches expected
↓
Use if valid; else build & upload new hash
Pro tip: Use fast hashers like xxHash for lookups, crypto-strong (SHA-256/BLAKE3) for storage.
2. Sandboxing for Isolation
Sandboxes prevent builds from reading/writing outside their scope, ensuring hermeticity.
How it works:
Filesystem: Mount read-only inputs + writable output/symlink dirs. Use chroot, namespaces (Linux), or tools like Bubblewrap.
Network: Block outbound (e.g., seccomp filters). Fetch deps before sandbox.
Process: Limit CPU/memory, no privilege escalation.