The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): remote backend probe no longer puts user, $HOME and cwd into the system prompt
teknium1af66d5db155d
diff --git a/agent/prompt_builder.py b/agent/prompt_builder.pyindex 982da2f8e2f..6c0b6edc577 100644--- a/agent/prompt_builder.py+++ b/agent/prompt_builder.py@@ -904,10 +904,11 @@ def _tenv_read(name: str, default: str = "") -> str:_BACKEND_IMAGE_KEYS = {b: f"{b}_image" for b in ("docker", "singularity", "modal", "daytona")}# (config key, default) pairs forwarded to _create_environment's container_config.# Single-line POSIX probe; `2>/dev/null` keeps a missing binary from polluting output.+# OS/kernel only: the sandbox's user, $HOME and cwd are user-identifying and nothing consumes+# them — the model can `whoami && pwd` when a task actually needs them._BACKEND_PROBE_CMD = (- "printf 'os=%s\\nkernel=%s\\nhome=%s\\ncwd=%s\\nuser=%s\\n' \"$(uname -s 2>/dev/null || echo unknown)\" "- "\"$(uname -r 2>/dev/null || echo unknown)\" "- "\"$HOME\" \"$(pwd)\" \"$(whoami 2>/dev/null || id -un 2>/dev/null || echo unknown)\""+ "printf 'os=%s\\nkernel=%s\\n' \"$(uname -s 2>/dev/null || echo unknown)\" "+ "\"$(uname -r 2>/dev/null || echo unknown)\"")@@ -950,11 +951,8 @@ def _format_backend_probe(output: str) -> str:"""Render the probe's key=value lines as an indented summary ("" if nothing usable)."""parsed = {k.strip(): v.strip() for k, _, v in (line.partition("=") for line in output.splitlines() if "=" in line)}known = lambda key: parsed.get(key) if parsed.get(key) != "unknown" else None # noqa: E731- fields = (- ("OS", " ".join(x for x in (known("os"), known("kernel")) if x)),- ("User", known("user")), ("Home", parsed.get("home")), ("Working directory", parsed.get("cwd")),- )- return "\n".join(f" {label}: {value}" for label, value in fields if value)+ os_line = " ".join(x for x in (known("os"), known("kernel")) if x)+ return f" OS: {os_line}" if os_line else ""def _probe_remote_backend(env_type: str) -> str | None:@@ -1022,7 +1020,9 @@ def _remote_backend_hint(backend: str) -> str:if probe:return lead + (f"this {backend} environment — NOT on the machine where Hermes itself is running. The host OS, "- f"home, and cwd of the Hermes process are irrelevant; only the following backend state matters:\n{probe}"+ f"home, and cwd of the Hermes process are irrelevant; only the following backend state matters:\n{probe}\n"+ f" The sandbox's current user, $HOME, and working directory are not listed here; if you need them, "+ f"probe directly with a terminal call like `whoami && pwd`.")description = (_BACKEND_FALLBACK_DESCRIPTIONS.get(backend)@@ -1031,7 +1031,7 @@ def _remote_backend_hint(backend: str) -> str:)return lead + (f"{description} — NOT on the machine where Hermes itself runs. The backend probe didn't respond at "- f"prompt-build time, so the sandbox's current user, $HOME, and working directory are unknown from here. "+ f"prompt-build time, so the sandbox's OS, current user, $HOME, and working directory are unknown from here. "f"If you need them, probe directly with a terminal call like `uname -a && whoami && pwd`.")diff --git a/tests/agent/test_prompt_builder.py b/tests/agent/test_prompt_builder.pyindex 441af945401..8e2e5b45758 100644--- a/tests/agent/test_prompt_builder.py+++ b/tests/agent/test_prompt_builder.py@@ -895,7 +895,34 @@ class TestEnvironmentHints:assert created.get("env_type") == "docker"assert line is not Noneassert "Linux 6.8.0" in line- assert "root" in line++ def test_remote_backend_probe_carries_no_user_home_cwd(self, monkeypatch):+ """#117262: the sandbox's user, $HOME and cwd are user-identifying metadata that+ nothing consumes — the probe must neither ask for them nor render them. The+ fake sandbox answers with the legacy full payload so a formatter that still+ renders those keys is caught too."""+ import agent.prompt_builder as _pb+ import tools.terminal_tool_backends as _tt+ import tools.terminal_tool_lifecycle as _lc++ monkeypatch.setenv("TERMINAL_ENV", "docker")+ _pb._clear_backend_probe_cache()+ ran = {}++ class _FakeEnv:+ def execute(self, cmd, timeout=None):+ ran["cmd"] = cmd+ return {"returncode": 0, "output": "os=Linux\nkernel=6.8.0\nhome=/home/alice\ncwd=/srv/secret\nuser=alice\n"}++ monkeypatch.setattr(_tt, "_create_environment", lambda **kw: _FakeEnv())+ monkeypatch.setattr(_lc, "_cleanup_env", lambda env, **kw: None)++ hint = _pb._remote_backend_hint("docker")+ assert "OS: Linux 6.8.0" in hint+ for probe_token in ("whoami", "id -un", "$HOME", "pwd"):+ assert probe_token not in ran["cmd"]+ for leaked in ("User:", "Home:", "Working directory:", "alice", "/srv/secret"):+ assert leaked not in hintdef test_probe_remote_backend_tears_down_its_sandbox(self, monkeypatch):"""THE BUG: the probe leaked a second, permanently idle sandbox.