bash: image_env() util + subprocess.run env parity (drop clean_env flag)#154
Merged
Conversation
Follow-up to #151 per maintainer review: a boolean flag on run/run_stream adds cognitive cost to a tool that should read like subprocess.run, and the mechanism to pick an environment already exists — you pass env=. So instead of a mode flag: - bash.run/run_stream env= now follows subprocess.run exactly: omit it to inherit the worker's environment (right for bundle tools — the claude CLI, bundled rg), pass a dict to REPLACE it wholesale. No merge, no flag. (No production caller passed a partial env expecting a merge — only tests, updated to the replace idiom.) - image_env() is the extracted helper the swebench scorer hand-rolled: get_env_without_agentix() plus BASH_ENV -> ~/.bashrc (derived from the RESULT env's HOME, so a stripped-and-restored or overridden HOME picks the right rc file). Canonical name: agentix.bash.image_env, re-exported next to run(); implemented in agentix.runtime.shared.env because that module owns the ADDED/SAVED contract and a cross-plugin import would not resolve statically in the pkgutil namespace layout. swebench's score.py now calls it instead of its private copy. - The shell binary follows the env's PATH like everything else the command resolves: the default worker env lists the bundled bash first (behavior unchanged for bundle calls), while an image_env() PATH selects the image's own bash — its restored LD_PRELOAD targets that binary, not the Nix one. image_env() reads the calling process's live environment, so it is only meaningful inside the sandbox; the docs show the host-side recipe (env = await c.remote(image_env)) and warn that evaluating it host-side would ship the host's environment into the container. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why (maintainer review of #151)
A boolean
clean_envflag onrun/run_streamadds cognitive cost to a tool that should read exactly likesubprocess.run— and the mechanism to choose an environment already exists: you passenv=. The right shape is a util you pass as a value, not a mode that forks behavior.What
env=now followssubprocess.runexactly: omit it to inherit the worker's environment (right for bundle tools — the claude CLI, bundledrg); pass a dict to replace it wholesale. No merge, no flag. (No production caller passed a partial env expecting a merge; tests updated to the replace idiom.)image_env()is the extracted helper the swebench scorer hand-rolled:get_env_without_agentix()plusBASH_ENV → ~/.bashrc— derived from the result env'sHOME, so a stripped-and-restored or overridden HOME picks the right rc file. Canonical nameagentix.bash.image_env, re-exported next torun(); implemented inagentix.runtime.shared.envbecause that module owns theADDED/SAVEDcontract and a cross-plugin import doesn't resolve statically in the pkgutil-namespace layout (pyright).score.pynow calls it instead of its private copy.PATHlike everything else the command resolves: the default worker env lists the bundled bash first (bundle behavior unchanged), while animage_env()PATH selects the image's own bash — its restoredLD_PRELOADtargets that binary, not the Nix one. Value-driven, no mode.Boundary
image_env()reads the calling process's live environment — only meaningful inside the sandbox. Sandbox-side code composes directly (run(cmd, env=image_env())); a host fetches it over the wire (env = await c.remote(image_env)). The docs warn that evaluating it host-side would ship the host's environment (PATH/HOME/secrets) into the container — the co-author review caught that the first draft's doc example had exactly this footgun.Dual-reviewed (Codex + adversarial pass); all three confirmed findings fixed: host-side-evaluation footgun in the docs, shell selection dropped in the redesign (now PATH-driven),
HOME-override picking the wrong.bashrc.🤖 Generated with Claude Code