fix(execute_code): forward docker_env/forward_env/extra_args to spawned containers#30097
fix(execute_code): forward docker_env/forward_env/extra_args to spawned containers#30097elozadaf wants to merge 1 commit into
Conversation
…ed containers
_get_or_create_env() builds container_config for the execute_code sandbox but
omitted docker_env, docker_forward_env and docker_extra_args. terminal_tool
already forwards all three (terminal_tool.py container_config build), so
execute_code-spawned containers ran without host env vars, forwarded env, or
extra docker flags while terminal-spawned ones had them.
Concrete symptom: tools relying on a host service from inside an execute_code
container fail — e.g. a keyring-backed CLI cannot reach the host secret
service because the docker-default AppArmor profile blocks D-Bus, and the
--security-opt apparmor=unconfined override (a docker_extra_args value) never
reached the container.
Add the three keys to container_config, defaulting to {} / [] / [] so the
change is a no-op for setups that don't configure them. Brings execute_code
to parity with terminal_tool.
Adds tests/tools/test_code_execution_container_config.py (6 tests), mirroring
the existing test_file_tools_container_config.py.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
mohamedorigami-jpg
left a comment
There was a problem hiding this comment.
This is a clean fix for a real bug. The terminal_tool already forwarded docker_env / docker_forward_env / docker_extra_args to spawned containers, but code_execution_tool's equivalent path was missing them. This meant execute_code containers ran without env vars or custom docker flags that the user had configured.
Code change: 3 lines in container_config dict, matching the same keys terminal_tool uses. The defaults ({} and []) match the upstream convention.
Tests: 6 test cases cover the happy path for each key plus the default-behavior path for each. The test structure mirrors the existing test_file_tools_container_config.py which is the right pattern to follow.
One minor thing: the comment block at lines 624-629 is detailed (date, symptom, root cause). That's helpful for future readers but it's more of a commit message than an inline comment. If the team prefers minimal inline comments, this could be trimmed to just # Forward docker_env/forward_env/extra_args so execute_code containers match terminal_tool behavior. Not a blocker -- the comment is accurate.`
What does this PR do?
_get_or_create_env()incode_execution_tool.pybuilds thecontainer_configdict for theexecute_codesandbox, but omitted three docker keys.terminal_tool.pyalready forwards all three when it builds its owncontainer_config, soexecute_code-spawned containers ran without host env vars, forwarded env, or extra docker flags — whileterminal-spawned containers had them. The two tools spawn the same kind of container but were not at parity.This adds the missing keys:
Concrete symptom: a tool that depends on a host service from inside an
execute_codecontainer fails — e.g. a keyring-backed CLI can't reach the host secret service because the docker-default AppArmor profile blocks D-Bus, and the--security-opt apparmor=unconfinedoverride (adocker_extra_argsvalue) never reached the container. The same code under theterminaltool worked.The keys default to
{}/[]/[], so this is a no-op for any setup that doesn't configure them.Related Issue
No tracking issue — found while debugging a host-service integration that worked under
terminalbut failed underexecute_code.Fixes #
Type of Change
Changes Made
tools/code_execution_tool.py—_get_or_create_env()addsdocker_env,docker_forward_env,docker_extra_argstocontainer_configtests/tools/test_code_execution_container_config.py— 6 tests (forwarding + defaults), mirroring the existingtest_file_tools_container_config.pyHow to Test
pytest tests/tools/test_code_execution_container_config.py -q— 6 passed.docker_extra_args/docker_env/docker_forward_envin the env config; the container theexecute_codetool spawns now receives them (previously onlyterminal-spawned containers did).Checklist
Code
fix(scope):)tests/tools/test_code_execution_container_config.py: 6 passedDocumentation & Housekeeping
cli-config.yaml.exampleif I added/changed config keys — N/A (keys already exist and are consumed byterminal_tool)CONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — N/A