Skip to content

Replace exec-suid environ modes with env overrides - #16

Merged
ConnorNelson merged 1 commit into
mainfrom
codex/safe-env-overrides
Jun 11, 2026
Merged

Replace exec-suid environ modes with env overrides#16
ConnorNelson merged 1 commit into
mainfrom
codex/safe-env-overrides

Conversation

@ConnorNelson

@ConnorNelson ConnorNelson commented Jun 11, 2026

Copy link
Copy Markdown
Member

Summary

  • keep --environ=none/all/safe temporarily as deprecated compatibility options
  • add repeated --env KEY=VALUE shebang overrides for explicit environment variables
  • source the default safe PATH from /etc/environment, with a Debian/Ubuntu root PATH fallback
  • skip /etc/environment PATH lookup when --env PATH=... is explicitly provided

Rationale

exec-suid previously required PATH to be present in /proc/1/environ. That works when PID 1 is the container process, but it breaks in runtimes where PID 1 is platform infrastructure or a minimal init without image ENV values. /etc/environment is a better image-owned source for this value, and a fixed fallback keeps safe mode usable even when that file is absent.

The new --env option intentionally only supports explicit KEY=VALUE assignments. The shebang line is still split on whitespace, so values containing whitespace are intentionally not supported.

The fallback PATH is /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin, matching Debian/Ubuntu's root ENV_SUPATH without Ubuntu's snap-specific suffix. Python's os.defpath is narrower (/bin:/usr/bin), and Ubuntu sudo's secure_path adds /snap/bin, so the Debian root path is the better general-purpose default here.

Validation

  • docker build -t exec-suid-env-pr /tmp/exec-suid-pr && docker run --rm exec-suid-env-pr passes: 19 tests
  • git diff --check

Note: cargo fmt --check was not applied because the existing upstream source is not rustfmt-formatted and rustfmt would rewrite unrelated lines.

@ConnorNelson
ConnorNelson force-pushed the codex/safe-env-overrides branch 18 times, most recently from 22aecd4 to 12ecccc Compare June 11, 2026 19:33
@zardus

zardus commented Jun 11, 2026

Copy link
Copy Markdown
Member

Can we keep backwards compatibility in the normal case? We have a lot of challenges using this now...

@ConnorNelson
ConnorNelson force-pushed the codex/safe-env-overrides branch from 12ecccc to ec1ce4f Compare June 11, 2026 19:42
@ConnorNelson

Copy link
Copy Markdown
Member Author

Sure, I'll mark it deprecated instead for now, until we've stopped using the feature.

I just took a quick glance at:

My guess is it won't be so difficult to have some agents migrate the code in the future. I think --environ=none is kind of silly. I know I've seen some agents think they need to use it to be safe, but you really don't: the default is safe.

And --environ=all is of course inherently unsafe and can always lead to problems. Of course, we have challenges that like that and/or accept that limitation. I'm not sure if a custom really dumb exec-suid makes the most sense for those challenges (it would be really easy to write), or maybe if all of them really just want --env PATH=$PATH or something like that, we can add support for that.

@ConnorNelson
ConnorNelson marked this pull request as ready for review June 11, 2026 19:55
@ConnorNelson ConnorNelson changed the title [codex] Replace exec-suid environ modes with env overrides Replace exec-suid environ modes with env overrides Jun 11, 2026
@ConnorNelson
ConnorNelson merged commit 481fdfc into main Jun 11, 2026
1 check passed
@ConnorNelson
ConnorNelson deleted the codex/safe-env-overrides branch June 11, 2026 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants