← Back to Pull requests

refactor: run sandboxed scripts through a sandbox runner #2888

Open
baszalmstra opened this pull request with 353 lines diff across 4 files
View on GitHub
baszalmstra baszalmstra commented on Oct 20, 2026 20:59 UTC
Author

Stacked on #2885.

run_script has two execution paths. Without --sandbox it runs the wrapper through a Session; with --sandbox it falls back to a host-side helper that spawns rattler-sandbox itself, so the sandbox bypasses the runner entirely and anything that configures a runner (tests, library callers) silently loses it. The fallback also only knows about the build directory, so package tests never ran sandboxed, and a missing rattler-sandbox only showed up after every environment was solved.

This turns sandboxing into a runner. SandboxRunner wraps a LocalRunner and prefixes every exec with rattler-sandbox, the static policy from the configuration, and the access derived from the session mounts: a writable mount gets read, write and execute, a read-only mount gets read. SandboxRunner::new checks the platform and looks up the executable, so --sandbox on Windows warns and runs locally, and a missing rattler-sandbox fails before solving. Build, staging and package tests all pass their mounts through the new Mounts builder (Mounts::new().writable(build_dir).read_only(recipe_dir)), which keeps insertion order and nothing else; the sandbox runner rejects a mount whose guest path differs from its host path because it cannot remap paths.

The host-side fallback, run_process_with_replacements, SandboxConfiguration::with_cwd and ShellDialect::supports_sandbox are gone, and BuildLogSink no longer captures output in memory because nothing read it.

Two behaviour changes worth knowing about: package tests now run under the sandbox too, and the recipe directory is always readable, which matters with --overwrite-default-sandbox-config.

Testing

Unit tests cover the sandbox argv for writable and read-only mounts, rejection of unmirrored mounts, the platform and executable checks at construction and in check_usable, and run_script confined through a fake rattler-sandbox on PATH.

The second commit adds the first end-to-end coverage of --sandbox: two recipes try to write a marker under the home directory (the default policy leaves /tmp writable, so that is not a useful target), one from the build script and one from a package test. Each test first builds without the sandbox to show the marker appears, then with it to show the build fails and the marker does not. rattler-sandbox is now a Unix dependency of the pixi workspace, and the Ubuntu CI job lifts the AppArmor restriction on unprivileged user namespaces first, which 24.04 enables by default and which the sandbox needs. Both tests pass natively on Linux (WSL Ubuntu, "Read-only file system" from the script); macOS is only covered by CI. Please look closely at the derived grants in Directories::session_mounts and the test call sites; that is where the old behaviour could differ.

Diff: 353 lines (+264 / -89) across 4 files Reviewer: None requested Review duration: 61383m
All Vouch review confidence checks passed
Residual risk 0.36 = Change Risk (0.61) × (1 − Review Confidence (0.42)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.61 · 353 lines diff across 4 files
0.61
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 10%
42%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.351
Shallow Review Depth shallow_review_depth
0.344
No Reviewer Assigned no_reviewer_assigned
0.120
Real PR Conversation Timeline
1 comments
"Review active on #2888"
general weight: 0.35
Reviewers
None requested
Assignees
baszalmstra baszalmstra
Labels
risk: medium confidence: 42.2% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 61.5% (MEDIUM) · Higher = larger blast radius
61.5%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 42.2% · Lower = rushed or shallow review
42.2%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 35.5% · Moderate risk
35.5%