Closes#257. Based on main (after #292 and #293). Part of #253 · MVP-0.
Why
Nearly every stage only reads customer code — Semgrep, gitleaks, Syft, Ruff and the PLC parser parse files. Four stages instead run it, inside the agent container, as root, with the Mongo URI, the Keycloak and registry client secrets and the LLM key in the process environment, and a database user that reaches every tenant:
Stage
What executes
cargo clippy
compiles the crate, so build.rs and proc macros run
ESLint
the repo's own node_modules/.bin/eslint, plus JavaScript config files
pip-compile
builds sdists to read metadata, running setup.py
Firmware reproducible build
the project's build system, through Nix with sandbox = false
Scanning hostile code is the product's whole job, so "the repo we were handed is hostile" is the expected case, not the edge case.
What changes
compliance_core::ExecPolicy gates all four. Off by default; PW_ALLOW_UNTRUSTED_CODE_EXEC=1 re-enables them for single-tenant or sandboxed deployments, and a hardened deployment ignores it — same shape as the on-premise opt-out in #256. Skipped stages log a line naming the stage and the flag rather than failing.
Coverage is barely affected. Dependency resolution continues: npm already ran --package-lock-only --ignore-scripts, and cargo generate-lockfile and cargo metadata resolve without compiling, so the SBOM is unchanged. What is lost is clippy/ESLint lint findings — quality warnings, not security findings, and both are duplicated by Semgrep's rules for the same languages — and the sealed firmware build, whose complete SBOM arrives instead as an imported Firmwerk bundle (#280), built on the customer's side where running their build is their own risk.
pipeline::tool_cmd is now how every external tool spawns:
an empty environment plus a named allowlist (PATH, HOME, TMPDIR, LANG, and a tool's own cache variables such as CARGO_HOME). Adding a variable is a deliberate edit to one file, so a future secret cannot be inherited by accident;
kill_on_drop(true): dropping a tokio Child does not kill the process, so a timed-out semgrep kept running with its CPU, memory and clone directory. The comment in lint/mod.rs asserting it was SIGKILLed on drop was wrong;
run_bounded for the lockfile and metadata commands, which had no timeout at all.
cargo test --lib → 330 + 71 + 9 pass (werkbank-exec unchanged at 28).
New tests: the policy defaults and its skip message; the tool-environment allowlist contains nothing secret-shaped; and a gating test that builds a repo with both a Cargo.toml and a stub node_modules/.bin/eslint that would fail the test if it ran — the scan returns empty and never executes it.
Docs: docs/guide/scanning.md gains "What the scanner runs on your code", and .env.example documents the flag.
Follow-up
The stages return as sandboxed Werkbank jobs — a separate container, no secrets, no network — which is the right home for running a customer's build. That belongs with the Werkbank work in R1 rather than here.
Closes #257. Based on `main` (after #292 and #293). Part of #253 · MVP-0.
## Why
Nearly every stage only *reads* customer code — Semgrep, gitleaks, Syft, Ruff and the PLC parser parse files. Four stages instead **run** it, inside the agent container, as root, with the Mongo URI, the Keycloak and registry client secrets and the LLM key in the process environment, and a database user that reaches every tenant:
| Stage | What executes |
|---|---|
| `cargo clippy` | compiles the crate, so `build.rs` and proc macros run |
| ESLint | the repo's own `node_modules/.bin/eslint`, plus JavaScript config files |
| `pip-compile` | builds sdists to read metadata, running `setup.py` |
| Firmware reproducible build | the project's build system, through Nix with `sandbox = false` |
Scanning hostile code is the product's whole job, so "the repo we were handed is hostile" is the expected case, not the edge case.
## What changes
**`compliance_core::ExecPolicy`** gates all four. Off by default; `PW_ALLOW_UNTRUSTED_CODE_EXEC=1` re-enables them for single-tenant or sandboxed deployments, and a hardened deployment ignores it — same shape as the on-premise opt-out in #256. Skipped stages log a line naming the stage and the flag rather than failing.
**Coverage is barely affected.** Dependency resolution continues: npm already ran `--package-lock-only --ignore-scripts`, and `cargo generate-lockfile` and `cargo metadata` resolve without compiling, so the SBOM is unchanged. What is lost is clippy/ESLint lint findings — quality warnings, not security findings, and both are duplicated by Semgrep's rules for the same languages — and the sealed firmware build, whose complete SBOM arrives instead as an imported Firmwerk bundle (#280), built on the customer's side where running their build is their own risk.
**`pipeline::tool_cmd`** is now how every external tool spawns:
- an empty environment plus a named allowlist (`PATH`, `HOME`, `TMPDIR`, `LANG`, and a tool's own cache variables such as `CARGO_HOME`). Adding a variable is a deliberate edit to one file, so a future secret cannot be inherited by accident;
- `kill_on_drop(true)`: dropping a tokio `Child` does **not** kill the process, so a timed-out semgrep kept running with its CPU, memory and clone directory. The comment in `lint/mod.rs` asserting it was SIGKILLed on drop was wrong;
- `run_bounded` for the lockfile and metadata commands, which had no timeout at all.
## Verification
- `cargo fmt --all --check` and `cargo clippy -p compliance-core -p compliance-agent -p compliance-mcp -p werkbank-exec -p control-map -- -D warnings` clean.
- `cargo test --lib` → **330 + 71 + 9 pass** (werkbank-exec unchanged at 28).
- New tests: the policy defaults and its skip message; the tool-environment allowlist contains nothing secret-shaped; and a gating test that builds a repo with both a `Cargo.toml` and a stub `node_modules/.bin/eslint` that would fail the test if it ran — the scan returns empty and never executes it.
- Docs: `docs/guide/scanning.md` gains "What the scanner runs on your code", and `.env.example` documents the flag.
## Follow-up
The stages return as **sandboxed Werkbank jobs** — a separate container, no secrets, no network — which is the right home for running a customer's build. That belongs with the Werkbank work in R1 rather than here.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
Most of the pipeline reads customer code. Four stages ran it — inside the
agent container, as root, with the Mongo URI, the Keycloak and registry client
secrets and the LLM key in the environment, and a database user that reaches
every tenant:
- `cargo clippy` compiles the repo, so its `build.rs` and proc macros run;
- ESLint is executed from the repo's own `node_modules/.bin`, and its config
files are JavaScript;
- `pip-compile` builds source distributions to read metadata, running `setup.py`;
- the firmware reproducible build shells out to Nix with `sandbox = false`.
Scanning hostile code is the job, so new `compliance_core::ExecPolicy` gates
all four. It is off by default and a hardened deployment ignores the
`PW_ALLOW_UNTRUSTED_CODE_EXEC` opt-out, which stays for single-tenant and
sandboxed deployments. Dependency resolution is unaffected: npm already runs
`--package-lock-only --ignore-scripts`, and `cargo generate-lockfile` and
`cargo metadata` resolve without compiling. A complete firmware SBOM comes from
an imported Firmwerk bundle (#280) instead of a build here.
Every external tool now spawns through `pipeline::tool_cmd`:
- an empty environment plus a named allowlist (PATH, HOME, TMPDIR, LANG, and a
tool's own cache variables), so semgrep, syft, gitleaks, ruff, cargo and npm
no longer inherit the agent's credentials;
- `kill_on_drop`, because a tokio child outlives its timeout otherwise — the
comment claiming a timed-out scanner was SIGKILLed was wrong;
- a bounded run for the lockfile and metadata commands, which had no timeout.
Part of #253 · MVP-0 safety baseline.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Closes #257. Based on
main(after #292 and #293). Part of #253 · MVP-0.Why
Nearly every stage only reads customer code — Semgrep, gitleaks, Syft, Ruff and the PLC parser parse files. Four stages instead run it, inside the agent container, as root, with the Mongo URI, the Keycloak and registry client secrets and the LLM key in the process environment, and a database user that reaches every tenant:
cargo clippybuild.rsand proc macros runnode_modules/.bin/eslint, plus JavaScript config filespip-compilesetup.pysandbox = falseScanning hostile code is the product's whole job, so "the repo we were handed is hostile" is the expected case, not the edge case.
What changes
compliance_core::ExecPolicygates all four. Off by default;PW_ALLOW_UNTRUSTED_CODE_EXEC=1re-enables them for single-tenant or sandboxed deployments, and a hardened deployment ignores it — same shape as the on-premise opt-out in #256. Skipped stages log a line naming the stage and the flag rather than failing.Coverage is barely affected. Dependency resolution continues: npm already ran
--package-lock-only --ignore-scripts, andcargo generate-lockfileandcargo metadataresolve without compiling, so the SBOM is unchanged. What is lost is clippy/ESLint lint findings — quality warnings, not security findings, and both are duplicated by Semgrep's rules for the same languages — and the sealed firmware build, whose complete SBOM arrives instead as an imported Firmwerk bundle (#280), built on the customer's side where running their build is their own risk.pipeline::tool_cmdis now how every external tool spawns:PATH,HOME,TMPDIR,LANG, and a tool's own cache variables such asCARGO_HOME). Adding a variable is a deliberate edit to one file, so a future secret cannot be inherited by accident;kill_on_drop(true): dropping a tokioChilddoes not kill the process, so a timed-out semgrep kept running with its CPU, memory and clone directory. The comment inlint/mod.rsasserting it was SIGKILLed on drop was wrong;run_boundedfor the lockfile and metadata commands, which had no timeout at all.Verification
cargo fmt --all --checkandcargo clippy -p compliance-core -p compliance-agent -p compliance-mcp -p werkbank-exec -p control-map -- -D warningsclean.cargo test --lib→ 330 + 71 + 9 pass (werkbank-exec unchanged at 28).Cargo.tomland a stubnode_modules/.bin/eslintthat would fail the test if it ran — the scan returns empty and never executes it.docs/guide/scanning.mdgains "What the scanner runs on your code", and.env.exampledocuments the flag.Follow-up
The stages return as sandboxed Werkbank jobs — a separate container, no secrets, no network — which is the right home for running a customer's build. That belongs with the Werkbank work in R1 rather than here.
🤖 Generated with Claude Code
https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
5975ba45f9tobf89e57b58