From e5bd25c73f661e304edd3192d4d5050d7bbaee01 Mon Sep 17 00:00:00 2001 From: teknium1 Date: Wed, 25 Feb 2026 21:16:15 -0800 Subject: [PATCH] Fix: #41 --- tools/code_execution_tool.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tools/code_execution_tool.py b/tools/code_execution_tool.py index c58951fd6..aa64c802f 100644 --- a/tools/code_execution_tool.py +++ b/tools/code_execution_tool.py @@ -381,7 +381,20 @@ def execute_code( rpc_thread.start() # --- Spawn child process --- - child_env = os.environ.copy() + # Build a minimal environment for the child. We intentionally exclude + # API keys and tokens to prevent credential exfiltration from LLM- + # generated scripts. The child accesses tools via RPC, not direct API. + _SAFE_ENV_PREFIXES = ("PATH", "HOME", "USER", "LANG", "LC_", "TERM", + "TMPDIR", "TMP", "TEMP", "SHELL", "LOGNAME", + "XDG_", "PYTHONPATH", "VIRTUAL_ENV", "CONDA") + _SECRET_SUBSTRINGS = ("KEY", "TOKEN", "SECRET", "PASSWORD", "CREDENTIAL", + "PASSWD", "AUTH") + child_env = {} + for k, v in os.environ.items(): + if any(s in k.upper() for s in _SECRET_SUBSTRINGS): + continue + if any(k.startswith(p) for p in _SAFE_ENV_PREFIXES): + child_env[k] = v child_env["HERMES_RPC_SOCKET"] = sock_path child_env["PYTHONDONTWRITEBYTECODE"] = "1"