From 23bc642c8296829f42737be6c40077ea70ec5867 Mon Sep 17 00:00:00 2001 From: anastazya Date: Sat, 14 Mar 2026 15:23:09 +0100 Subject: [PATCH] fix: add project root to PYTHONPATH in execute_code sandbox The execute_code sandbox spawns a child process with cwd set to a temporary directory, but never adds the hermes-agent project root to PYTHONPATH. This makes project-root modules like minisweagent_path unreachable from sandboxed scripts, causing ImportError when the agent runs self-diagnostic or analysis code via execute_code. Fix by prepending the hermes-agent root directory to PYTHONPATH in the child process environment. Co-Authored-By: Claude Opus 4.6 (1M context) --- tools/code_execution_tool.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/code_execution_tool.py b/tools/code_execution_tool.py index b7fac539c..f25c983f1 100644 --- a/tools/code_execution_tool.py +++ b/tools/code_execution_tool.py @@ -440,6 +440,11 @@ def execute_code( child_env[k] = v child_env["HERMES_RPC_SOCKET"] = sock_path child_env["PYTHONDONTWRITEBYTECODE"] = "1" + # Ensure the hermes-agent root is importable in the sandbox so + # modules like minisweagent_path are available to child scripts. + _hermes_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + _existing_pp = child_env.get("PYTHONPATH", "") + child_env["PYTHONPATH"] = _hermes_root + (os.pathsep + _existing_pp if _existing_pp else "") # Inject user's configured timezone so datetime.now() in sandboxed # code reflects the correct wall-clock time. _tz_name = os.getenv("HERMES_TIMEZONE", "").strip()