feat: Add support for environment protection (scrubbing) (#327)

* feat: Add support for environment variable protection for sandbox

* chore: Update dangerous env var list

* fix: Split profiles for improved environment protection

* fix: pipx sandbox profile separation

* chore: Show sandbox scrub info on error exit

* fix: Code review fixes

* test: Add e2e for sandbox environment scrubbing
This commit is contained in:
Abhisek Datta
2026-06-11 11:40:33 +05:30
committed by GitHub
parent 7620097613
commit c7244f921a
39 changed files with 1385 additions and 49 deletions
+17
View File
@@ -14,6 +14,14 @@ type transparentExit interface {
IsSignaled() bool
}
// scrubbedEnvReporter is optionally satisfied by a transparent exit error to
// surface how many environment variables the sandbox scrubbed from the failed
// run. Kept separate from transparentExit so older implementations still
// classify as transparent.
type scrubbedEnvReporter interface {
ScrubbedEnvCount() int
}
type exitDecision struct {
transparent bool
notice bool
@@ -34,6 +42,15 @@ func classifyExit(err error) exitDecision {
if !te.IsSignaled() && verbosityLevel != VerbosityLevelSilent {
d.notice = true
d.message = "↳ pmg: " + te.Error()
// Env scrubbing produces no sandbox violation and the child's own
// error (e.g. a registry 401) does not point at the cause, so hint at
// it here. Names are not printed; they are at info level via --debug.
if sr, ok := te.(scrubbedEnvReporter); ok && sr.ScrubbedEnvCount() > 0 {
d.message += fmt.Sprintf(
"\n↳ pmg: sandbox scrubbed %d env var(s) (names via --debug, re-allow with --sandbox-allow env=NAME)",
sr.ScrubbedEnvCount())
}
}
return d
}