Skip to content

fix(config): let a process env set runtime option variables - #306

Merged
zastrowm merged 2 commits into
strands-agents:mainfrom
zastrowm:fix/process-env-runtime-options
Nov 5, 2026
Merged

zastrowm merged 2 commits into
strands-agents:mainfrom
zastrowm:fix/process-env-runtime-options

Conversation

@zastrowm

@zastrowm zastrowm commented Nov 4, 2026

Copy link
Copy Markdown
Member

Description

A process's own env can now set a runtime's option variables, such as NODE_OPTIONS, BASH_ENV, RUBYOPT, JAVA_TOOL_OPTIONS, and PYTHONPATH. Before this change, box.toml refused them with "env name ... is set by the box itself", but the box sets none of them.

[agent]
command = ["node", "app.js"]
env = { NODE_OPTIONS = "--require /opt/app/preload.cjs" }   # refused before, loads now
  • Why the refusal was there. reserved_workload_environment keeps a credential phantom out of a variable that makes a runtime load code. A ProcessSpec reused the same predicate. For an operator's literal value, the refusal protects nothing: the environment is composed, each process composes only its own env, and command can already state the same flags.
  • What stays refused. A credential phantom is refused for every name it was refused for before: reserved_workload_environment returns the same answer for every name. A ProcessSpec env still refuses the names Box sets itself, with the same message. It also refuses LD_* and DYLD_*, now with a message that names the dynamic loader, because Box's own aliases run in the box and their loader would read the value.
  • Library callers. check_workload_env agrees with a box.toml load, so it now accepts these names too. EnvRefusal::LoadsCode names only LD_* and DYLD_*.
  • Interface. This is a change to reserved_workload_environment's role, which AGENTS.md lists as frozen. The owner approved it. No configuration that loads today stops loading. docs/user/config.md and crates/box/AGENTS.md state the new rule.
Design notes
  • reserved_workload_environment keeps its meaning. It stays the set that a credential may not claim, and it is now built from loader_hook and box_owned_environment. The phantom path needs no change, and its existing test still pins all 16 names.
  • LD_* and DYLD_* stay refused in env. Accepting them would give one rule with no exception. They are kept refused because they are the one case where Box's own code would load what it did not choose, even though the aliases are contained, so it is not an escape.
  • Test-workload scripts. Their comments said that NODE_OPTIONS and PYTHONPATH are refused, and that is no longer true. The comments change. The scripts keep --jitless in command and STRANDS_LIB_DIR, because both still work and a change there is not part of this fix.

Related Issues

None.

Type of Change

New feature

Testing

  • env_accepts_a_runtime_option_variable and env_refuses_a_dynamic_loader_variable_and_says_why fail before the change and pass after it.

  • the_check_and_a_box_load_refuse_the_same_entries_with_the_same_reason loads a full box.toml and accepts 14 runtime option names in [agent] and in a stdio [mcp.<name>]. It fails before the change.

  • an_agent_runtime_option_reaches_the_agent_and_no_tool and an_agent_runtime_option_does_not_reach_an_mcp_server start a real box: the agent sees its NODE_OPTIONS, and no tool or stdio MCP server receives it.

  • macOS (arm64): cargo fmt --all --check, just clippy, and cargo test --workspace --all-features --no-fail-fast with TMPDIR=/private/var/tmp/boxtmp. Some containment fixtures refuse a temporary directory under the operator home or /private/tmp, on main too.

  • Linux (arm64): CI unit tests pass.

  • I ran the relevant suites (just check, or cargo test --workspace --all-features)

  • If I touched Rust, I ran cargo fmt --all and cargo clippy --workspace --all-targets --all-features -- -D warnings

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • My changes generate no new warnings

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

A `ProcessSpec` `env` refuses `NODE_OPTIONS`, `BASH_ENV`, `ENV`, `RUBYOPT`, `PERL5LIB`,
`PERL5OPT`, `GEM_PATH`, `CLASSPATH`, `JAVA_TOOL_OPTIONS`, `_JAVA_OPTIONS`, and every `PYTHON*`
name, with the error "is set by the box itself". The box sets none of these names. The refusal
comes from `reserved_workload_environment`, which keeps a credential phantom out of a variable
that makes a runtime load code. For an operator's literal in `env`, it protects nothing: the
environment is composed, each process composes only its own `env`, and `command` can already
state the same flags (`node --require x.cjs`). An operator who wants a runtime option must
rewrite `command`, and the refusal also catches harmless names such as `PYTHONUNBUFFERED`.

- `env.rs`: split the predicate into `box_owned_environment` (proxy routing, CA trust, `PWD`,
  `USER`, the OTLP exporter) and `loader_hook`. `reserved_workload_environment` is
  `loader_hook || box_owned_environment`, so it returns the same answer for every name, and a
  credential phantom is refused as before.
- `env.rs` `refused_name`: a `ProcessSpec` `env` refuses `box_owned_environment` names as
  `SetByBox`, with the old message. It refuses `LD_*` and `DYLD_*` as `LoadsCode`, with a message
  that names the dynamic loader, because Box's own aliases run in the box and their loader would
  read the value. It accepts every other runtime option variable.
- Library: `check_workload_env` uses `refused_name`, so it agrees with a `box.toml` load.
  `EnvRefusal::LoadsCode` now names only `LD_*` and `DYLD_*`, and its doc and
  `docs/design/containment.md` say so.
- Interface: `box.toml` accepts `env` names that it refused before. No configuration that loads
  today stops loading. `docs/user/config.md` and `crates/box/AGENTS.md` state the new rule.
- Test-workload comments no longer say that `NODE_OPTIONS` and `PYTHONPATH` are refused. The
  scripts do not change.

- `process.rs::env_accepts_a_runtime_option_variable`: 12 names load in `[agent]`, `[tool.x]`,
  and `[mcp.x]`. It fails before the change.
- `process.rs::env_refuses_a_dynamic_loader_variable_and_says_why`: `LD_PRELOAD`,
  `LD_LIBRARY_PATH`, and `DYLD_INSERT_LIBRARIES` are refused with the dynamic-loader message. It
  fails before the change.
- `config::tests::an_interpreter_hook_cannot_receive_a_phantom`: unchanged, and it still refuses
  all 16 names as a phantom.
- `library_env_check.rs::a_name_the_dynamic_loader_reads_is_refused_as_loading_code` and
  `a_runtime_option_variable_passes`: `check_workload_env` refuses 5 dynamic-loader names as
  `LoadsCode` and accepts 14 runtime option names.
- `library_env_check.rs::the_check_and_a_box_load_refuse_the_same_entries_with_the_same_reason`:
  a full `box.toml` load accepts the 14 runtime option names in `[agent]` and in a stdio
  `[mcp.<name>]`. It fails before the change.
- `box_programs.rs::an_agent_runtime_option_reaches_the_agent_and_no_tool` and
  `runtime_mcp_start.rs::an_agent_runtime_option_does_not_reach_an_mcp_server`: an `[agent] env`
  `NODE_OPTIONS` reaches the agent, and no tool or stdio MCP server receives it.
- Run on macOS (arm64): `cargo fmt --all --check`, `just clippy`, and
  `cargo test --workspace --all-features --no-fail-fast` with `TMPDIR=/private/var/tmp/boxtmp`.
  Fixtures in `profile_conformance`, `contains_exec_target`, and `run::contain::boundary` refuse a
  temporary directory under the operator home or `/private/tmp`, so a run with another `TMPDIR`
  fails there on `main` too.
- Linux: not run here. CI ran the Linux (arm64) unit tests.
Comment thread docs/user/config.md Resolved
@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

Assessment: Approve

Re-review at 1fe81aa. Since 3806961, the only change is a 4-line addition to docs/user/config.md, which resolves my earlier suggestion. I found nothing new.

Checked and held at this head
  • The new sentence is accurate:
    • The hosted Shell sets only PWD, HOME, and USER (broker/shell.rs:193-195).
    • The alias forwards only the source text and the trace context.
    • A tool's or the agent's real interpreter does get its own table's value, because a leaf composes from its own spec and the agent's spawned programs use ..caller.clone().
  • No code or test changed since the last review. The findings from 3806961 still hold: phantom refusal is unchanged, the change only loosens, LD_*/DYLD_* are still refused, reach stays per table, and the load and the library check agree.
  • Commit format: the new commit's body is empty, and that is fine. Root AGENTS.md asks for the ## Problem/## Solution/## Tests headings only on the first commit, and that commit still lacks them. The no-amend rule means this can't change on this branch.

The new sentence also stops an operator from expecting PYTHONPATH or BASH_ENV to affect calls that go through the aliases.

@zastrowm
zastrowm enabled auto-merge (squash) November 5, 2026 18:24

@kevin-orellana kevin-orellana left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed configuration validation, environment composition, process isolation, and compatibility at 1fe81aa. I found no actionable defects. I verified nine relevant tests passed in both Linux and macOS CI logs. Independent testing could not complete because the development desktop ran out of disk space.

@zastrowm
zastrowm merged commit 612a8a0 into strands-agents:main Nov 5, 2026
16 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area - Agent Containment bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants