Skip to content

fix(tools): preserve env overrides and cwd across macOS sandbox rewrite#3872

Merged
bug-ops merged 1 commit into
mainfrom
3871-sandbox-env
May 13, 2026
Merged

fix(tools): preserve env overrides and cwd across macOS sandbox rewrite#3872
bug-ops merged 1 commit into
mainfrom
3871-sandbox-env

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

@bug-ops bug-ops commented May 13, 2026

Summary

  • rewrite_command_with_sandbox_exec on macOS replaced the entire std::process::Command with Command::new(sandbox_exec) to prepend the sandbox wrapper. Only program + args were carried over; .env / .env_remove overrides and .current_dir were dropped on the floor.
  • Concrete impact, post-fix(tools): forward set_skill_env and set_effective_trust through CompositeExecutor #3870:
    • Skill secret env injection broken under sandbox: with [tools.sandbox] enabled = true (the default in production configs), cmd.envs(extra_env) set by build_bash_command was wiped before spawn. GITHUB_TOKEN injected for the github skill never reached gh; tool reported Token in default: invalid because gh fell back to hosts.yml (which has no oauth_token field).
    • Caller-configured current_dir discarded: any future / present .current_dir(...) on bash invocations was reset to the parent process cwd.
  • Capture program + args + envs + cwd before the in-place replacement, then replay envs and cwd onto the new Command. Added one regression test (rewrite_preserves_env_overrides_and_cwd) that sets .env, .env_remove, and .current_dir and asserts all three survive the rewrite.

Closes #3871. Restores the end-to-end flow originally targeted by #3870 (which fixed the propagation through CompositeExecutor but left the sandbox-side defect in place).

Test plan

  • cargo +nightly fmt --check
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo nextest run -p zeph-tools -E 'test(sandbox)' → 58 passed (incl. new regression)
  • cargo nextest run --workspace --lib --bins → 9323 passed
  • Manual macOS verification: with [tools.sandbox] enabled = true, ZEPH_SECRET_GITHUB_TOKEN in age vault, github skill trusted with x-requires-secrets: github_token, ask agent to run gh auth status and confirm source is (GH_TOKEN)/(GITHUB_TOKEN) (not (default)).

Notes

  • Linux Landlock backend does not use Command replacement (LSM ruleset attaches in-process), so this defect is macOS-specific. No change to linux.rs.
  • The wider design issue — skill secret env should reach the subprocess regardless of sandbox state — is now resolved end-to-end. Trust-gate forwarding (fix(tools): forward set_skill_env and set_effective_trust through CompositeExecutor #3870) and env preservation (this PR) together close the chain vault → available_custom_secrets → set_skill_env → ShellExecutor::skill_env → cmd.envs → sandbox-exec → bash.

rewrite_command_with_sandbox_exec replaces the whole std::process::Command
with `Command::new(sandbox_exec)` to prepend sandbox-exec to the program.
The replacement carried over only program + args; env overrides set via
.env / .env_remove and current_dir set via .current_dir were silently
dropped. Concrete impact, post #3869:

- Skill secret env injection through CompositeExecutor reached ShellExecutor
  and was applied via cmd.envs(extra_env) in build_bash_command. Then the
  sandbox rewrite wiped it. Subprocess spawned with parent env only, so
  GITHUB_TOKEN (and any other x-requires-secrets value) never reached gh.
- Any caller-configured cwd was likewise discarded.

Capture program, args, envs, and current_dir BEFORE the in-place replacement,
then replay envs and cwd onto the new Command. Adds a regression test that
sets env, env_remove, and current_dir, runs the rewrite, and asserts all
three survive.

Closes #3871.
@github-actions github-actions Bot added documentation Improvements or additions to documentation rust Rust code changes bug Something isn't working size/M Medium PR (51-200 lines) labels May 13, 2026
@bug-ops bug-ops enabled auto-merge (squash) May 13, 2026 16:40
@bug-ops bug-ops merged commit b87aa49 into main May 13, 2026
32 checks passed
@bug-ops bug-ops deleted the 3871-sandbox-env branch May 13, 2026 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation rust Rust code changes size/M Medium PR (51-200 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

macOS sandbox rewrite drops Command env overrides (skill secret env lost)

1 participant