feat(gateway): add gateway.terminal_backend sandbox override for messaging sessions#4816
Open
dsr-restyn wants to merge 2 commits into
Open
feat(gateway): add gateway.terminal_backend sandbox override for messaging sessions#4816dsr-restyn wants to merge 2 commits into
dsr-restyn wants to merge 2 commits into
Conversation
…aging sessions Closes NousResearch#4281. When gateway.terminal_backend is set in config.yaml, all gateway sessions use that backend instead of the global terminal.backend. The execute_code tool also respects the Docker backend when TERMINAL_ENV=docker, running the Python subprocess inside the configured container. A startup warning is emitted when the gateway runs with the local backend and no gateway override is configured. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- execute_code_docker: use named containers for proper timeout kill (zombie fix) - execute_code_docker: remove stale container_id variable - execute_code_docker: document interrupt limitation in docstring - sandbox_config: validate terminal_backend against known backends before applying - sandbox_config: log info when gateway backend override is applied - gateway/run.py: use module-level _gateway_raw_cfg instead of re-reading config.yaml - tests: add assertions for named container, docker kill on timeout, invalid backend rejection Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
e597c1b to
b13061a
Compare
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.
Summary
gateway.terminal_backendconfig key that overridesterminal.backendfor all gateway (Telegram, Discord, etc.) sessionsexecute_code— whenTERMINAL_ENV=docker, the Python subprocess runs inside the container via a UDS socket bind-mountgateway.sandbox_imageandgateway.sandbox_lifetimeconfig keysMotivation
Closes #4281.
The dangerous-command approval system explicitly skips approval checks when a container backend is active (the container is the security boundary). This means running the gateway with
terminal.backend: localgives no sandbox isolation AND no approval gate. This PR makes it easy to enforce Docker sandboxing for all gateway sessions without affecting local CLI usage.Changes
gateway/sandbox_config.py(new): helpers —apply_gateway_backend_to_env(),should_warn_insecure_gateway(),get_gateway_terminal_backend()tools/execute_code_docker.py(new): runs theexecute_codechild subprocess inside Docker with UDS socket bind-mounted for tool RPCgateway/run.py: apply gateway backend override at startup; emit warning when running with local backendhermes_cli/config.py: addgateway.terminal_backend,gateway.sandbox_image,gateway.sandbox_lifetimedefaultshermes_cli/status.py: show gateway sandbox backend + image in/statusoutputtests/gateway/test_sandbox_config.py(new): 12 unit tests for sandbox config helperstests/tools/test_execute_code_docker.py(new): 14 unit tests for Docker subprocess wrapper and routing logicTest Plan
pytest tests/tools/test_execute_code_docker.py tests/gateway/test_sandbox_config.py)TERMINAL_ENV=dockerenv varUsage
Notes for Reviewers
execute_code_docker.pywrapper uses--network=hostso the UDS RPC socket path is identical inside and outside the containerTERMINAL_ENV=dockerANDTERMINAL_DOCKER_IMAGEare set — so local CLI sessions are never affectedgateway.sandbox_lifetimekey is stored in config but lifetime enforcement (container cleanup) is left for a follow-up (the per-session task_id already provides isolation via existing DockerEnvironment)