Build track: M6 is your first green pnpm build / pnpm test inside an isolated runner (see M6 in build track).
A sandbox is a safe playground where generated code runs without risking your laptop or production. You run installs, builds, and tests there, then copy out only verified artifacts.
Neighbors: Build track · Chapter 06 — Code generation · Chapter 14 — Security · Chapter 17 — Build vs integrate
Approaches:
- Docker container (common): ephemeral container per job, non-root user, read-only base, writable
/workspace, no host mounts—or read-only mount of repo template. - Firecracker / VM (stronger isolation): higher cold start cost.
- Browser iframe (limited): good for visual preview, not for trusting arbitrary shell; never treat iframe as security boundary for malicious codegen.
Pipeline: copy patch bundle → pnpm install (with lockfile from template) → pnpm test → pnpm build → collect artifacts + logs. Error capture: stream stdout/stderr to object storage; cap size; redact secrets via regex.
sequenceDiagram
participant O as Orchestrator
participant S as Sandbox_runner
participant C as Container
participant L as Log_store
O->>S: job_bundle
S->>C: start_ephemeral
C-->>S: exit_code_logs
S->>L: persist_logs
S-->>O: result_pass_fail
docker run --rm -v $(pwd)/workspace:/workspace -w /workspace node:20 bash -lc "pnpm install && pnpm test" with seccomp profile and network egress deny except registry allowlist.
- Supply chain:
pnpm installin sandbox still fetches packages—pin lockfile and use verified registry proxy. - Timeouts: hung tests block workers—use
timeoutwrapper per command.
- Use multi-stage images: deps cached, app layer thin.
- Save
docker inspect-level metadata for audits.
Sandbox network policy is part of the threat model, not an optimization. Codegen+install can exfiltrate tokens if env vars leak—inject short-lived read-only creds only when needed.