Sandbox Software-Factory Commit Provenance and Inspection Tooling¶
Status: Accepted (Amends ADR 0002, ADR 0024, and ADR 0052)
We establish end-to-end Git commit provenance tracking for Modal sandboxes, stamping the software-factory revision and dirty working tree status across container environment variables, persistent machine version files, Modal tags, and snapshot registries, backed by an in-container diagnostic utility (check-software-factory / check-sf).
Context¶
Modal sandboxes are decoupled cloud environments provisioned by software-factory to host target repositories, developer tools, and AI agents. The container image layers (shared/image.py) and boot scripts (shared/startup.sh, scripts/setup.sh, shared/t3_usage_sync.py) are baked directly from the host software-factory checkout into the container filesystem.
When issues or behavioral regressions occur inside a sandbox (or when resuming an older snapshot), diagnosing the root cause previously suffered from an absence of origin metadata:
1. Target Repository Isolation: Inside the container, the cloned repository in /root/<repo-name> is the target application repository (e.g. sFactory0/my-app), not software-factory. There was no direct record indicating which revision of software-factory provisioned the container.
2. Snapshot Age Drift: Sandboxes captured as filesystem snapshots (--from-snapshot) preserve disk contents and baked scripts indefinitely. When resumed days or weeks later by a newer software-factory launcher, engineers could not distinguish between the snapshot's initial creation commit and the launcher's current commit.
3. Uncommitted Local Edits: During rapid development on software-factory, uncommitted host modifications in shared/startup.sh or sandbox/launcher.py were baked into sandboxes without recording dirty status, making comparisons against clean GitHub commits deceptive.
Decisions¶
- Host Provenance Resolution Seam (
resolve_host_software_factory_provenance): -
In
sandbox/launcher.py, implementedresolve_host_software_factory_provenance(repo_root)with a robust fallback hierarchy:- Respect explicit process environment variables (
SOFTWARE_FACTORY_COMMIT,SOFTWARE_FACTORY_COMMIT_SHORT,SOFTWARE_FACTORY_REF,SOFTWARE_FACTORY_DIRTY). - Query host Git repository via
git rev-parse HEAD,git rev-parse --short HEAD,git symbolic-ref --short HEAD(or--abbrev-ref), andgit status --porcelain. - Fall back safely to
"unknown","unknown","unknown","0"when.gitis unavailable (e.g. deployed control plane functions).
- Respect explicit process environment variables (
-
Container Injection and Modal Tagging:
SandboxLauncher.launch()injects the four provenance variables into the container environment dictionary.-
Attaches provenance metadata to Modal Sandbox
tags: -
In-Sandbox Persistence & Snapshot Lineage:
- In
shared/startup.sh, provenance variables are exported to/etc/environmentand~/.bashrcfor subshell and login consistency. -
Written to
/etc/software-factory-version.json. When resuming from a snapshot (RESUME_SNAPSHOT=1), the original creation commit is preserved asorigin_commitand the resumption launch commit is recorded asresumed_commit. -
In-Container Inspection Utility (
check-software-factory/check-sf): - Installed
/usr/local/bin/check-software-factoryand symlinked/usr/local/bin/check-sf. -
Formats provenance details and outputs an actionable GitHub comparison URL:
https://github.com/${GH_ORG_NAME:-sFactory0}/software-factory/compare/<commit>...main -
Snapshot Registry Integration:
record_snapshot()insandbox/snapshots.pycapturessoftware_factory_commitandsoftware_factory_dirty, ensuring snapshot metadata inmodal.Dictand local fallback retains factory lineage.
Consequences¶
- Engineers and agents inside sandboxes can instantly verify container provenance and view GitHub diffs via
check-software-factory. - Control plane listings and snapshot registries display container build revisions and dirty indicators without container entry.
- Resumed snapshots maintain unambiguous audit trails between original image creation and resumption time.
- Zero performance overhead or boot latency degradation.