The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
eval(core-tool-deferral): keep agents' crontab and HOME writes inside the run sandbox (#132314)
Teknium141cc0dbc86b
diff --git a/evals/core_tool_deferral/README.md b/evals/core_tool_deferral/README.mdindex 500676a8052..f8551c86fea 100644--- a/evals/core_tool_deferral/README.md+++ b/evals/core_tool_deferral/README.md@@ -20,7 +20,10 @@ Original verdict + full numbers: `results/SUMMARY.md` and the PR #97979 bodyOPENROUTER_API_KEY survives), seeded session DB (targets + decoys),deterministic desktop-surface stubs (desktop_ui emitter + agentcallbacks), computer_use/image_generate stubbed at the registry- handler. Terminal/files/cron/process/session-DB are REAL.+ handler. Terminal/files/cron/process/session-DB are REAL, but host+ side effects stay in the run dir (`sandbox.py`): HOME is the profile+ home (`TERMINAL_HOME_MODE=profile`), `crontab` is a file-backed shim+ first on PATH, and the systemd user bus is unset.Exit 3 = infra/config error (never scored).- `orchestrator.py` — battery runner: resume-safe, per-task walltimeouts, parallel cells, errored-record retry, 3-infra-abort fuse.@@ -31,15 +34,15 @@ Original verdict + full numbers: `results/SUMMARY.md` and the PR #97979 body```bash# 1. Two plain checkouts pinned to the SHAs under test (never pip install -e)-git worktree add /tmp/abdefer-base <baseline-sha>-git worktree add /tmp/abdefer-pr <pr-sha>+git worktree add "$TMPDIR/abdefer-base" <baseline-sha>+git worktree add "$TMPDIR/abdefer-pr" <pr-sha>-export ABDEFER_BASE_TREE=/tmp/abdefer-base-export ABDEFER_PR_TREE=/tmp/abdefer-pr+export ABDEFER_BASE_TREE="$TMPDIR/abdefer-base"+export ABDEFER_PR_TREE="$TMPDIR/abdefer-pr"export OPENROUTER_API_KEY=... # the only key the worker keeps# 2. Smoke one cheap cell first-python3 worker.py base openai/gpt-5.6-terra config_grep_distractor 1 /tmp/smoke.json+python3 worker.py base openai/gpt-5.6-terra config_grep_distractor 1 "$TMPDIR/smoke.json"# 3. Battery (per model; start with the STRONGEST model to validate variance)python3 orchestrator.py openai/gpt-5.6-terra 3 --parallel=5diff --git a/evals/core_tool_deferral/sandbox.py b/evals/core_tool_deferral/sandbox.pynew file mode 100644index 00000000000..7160dfb2619--- /dev/null+++ b/evals/core_tool_deferral/sandbox.py@@ -0,0 +1,52 @@+"""Keep an eval agent's host-level side effects inside the run's sandbox.++HERMES_HOME isolation covers Hermes state only. Tasks like "schedule it nightly at 2am" let+the agent reach the operator's real crontab, systemd user manager and home directory: a+past run of ``longrange_backup_pipeline`` left three nightly cron jobs and two scripts on the+operator's machine, pointing into run dirs that no longer existed.++``isolate_host`` uses the product's own contract for this (``TERMINAL_HOME_MODE=profile``+pins every terminal child's HOME to ``{HERMES_HOME}/home``), points the worker's own HOME+there too so in-process ``~`` expansion follows, puts a file-backed ``crontab`` first on+PATH, and drops the user-bus variables so ``systemctl --user`` cannot reach the real manager.+"""+import os+import stat++CRONTAB_FILE_ENV = "EVAL_CRONTAB_FILE"++_CRONTAB_SHIM = """#!/bin/sh+# Eval sandbox crontab: the usual CLI, backed by a file inside the run dir.+f="${EVAL_CRONTAB_FILE:?}"+case "$1" in+ -l) if [ -s "$f" ]; then cat "$f"; else echo "no crontab for $(id -un)" >&2; exit 1; fi ;;+ -r) rm -f "$f" ;;+ -e) "${VISUAL:-${EDITOR:-vi}}" "$f" ;;+ ""|-) cat > "$f" ;;+ *) cat "$1" > "$f" ;;+esac+"""+++def isolate_host(run_root: str, hermes_home: str) -> str:+ """Sandbox HOME, crontab and the systemd user bus for this process and its children.++ Returns the path of the file the sandboxed ``crontab`` reads and writes.+ """+ home = os.path.join(hermes_home, "home")+ bin_dir = os.path.join(run_root, "bin")+ os.makedirs(home, exist_ok=True)+ os.makedirs(bin_dir, exist_ok=True)+ shim = os.path.join(bin_dir, "crontab")+ with open(shim, "w", encoding="utf-8") as f:+ f.write(_CRONTAB_SHIM)+ os.chmod(shim, os.stat(shim).st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)++ crontab_file = os.path.join(run_root, "crontab")+ os.environ[CRONTAB_FILE_ENV] = crontab_file+ os.environ["PATH"] = bin_dir + os.pathsep + os.environ.get("PATH", "")+ os.environ["HOME"] = home+ os.environ["TERMINAL_HOME_MODE"] = "profile"+ for var in ("DBUS_SESSION_BUS_ADDRESS", "XDG_RUNTIME_DIR"):+ os.environ.pop(var, None)+ return crontab_filediff --git a/evals/core_tool_deferral/worker.py b/evals/core_tool_deferral/worker.pyindex c37a851a488..60fd5e2b99d 100644--- a/evals/core_tool_deferral/worker.py+++ b/evals/core_tool_deferral/worker.py@@ -34,11 +34,14 @@ for var in list(os.environ):os.environ.pop("FAL_KEY", None)os.environ.pop("HERMES_PROFILE", None)+from sandbox import isolate_host # noqa: E402+tmp_root = tempfile.mkdtemp(prefix=f"ab-{ARM}-{TASK_ID}-")hermes_home = os.path.join(tmp_root, ".hermes")workspace = os.path.join(tmp_root, "ws")os.makedirs(hermes_home)os.makedirs(workspace)+isolate_host(tmp_root, hermes_home)with open(os.path.join(hermes_home, "config.yaml"), "w", encoding="utf-8") as f:f.write("model:\n provider: openrouter\n model: %s\n" % MODEL)diff --git a/tests/evals/test_core_tool_deferral_sandbox.py b/tests/evals/test_core_tool_deferral_sandbox.pynew file mode 100644index 00000000000..be707fb53d1--- /dev/null+++ b/tests/evals/test_core_tool_deferral_sandbox.py@@ -0,0 +1,38 @@+"""The core-tool-deferral worker's host sandbox (evals/core_tool_deferral/sandbox.py).++A past live run let agents install real nightly cron jobs and write scripts into the+operator's real ~/.hermes. The contract: after isolate_host, a child shell's crontab and+HOME both resolve inside the run dir.+"""+from __future__ import annotations++import os+import subprocess+from pathlib import Path++import pytest++from evals.core_tool_deferral.sandbox import isolate_host++[email protected]("posix") # the crontab shim is a POSIX sh script+def test_child_shell_crontab_and_home_stay_inside_the_run_dir(tmp_path, monkeypatch):+ monkeypatch.setattr(os, "environ", dict(os.environ))+ run_root = tmp_path / "run"+ hermes_home = run_root / ".hermes"+ hermes_home.mkdir(parents=True)++ crontab_file = isolate_host(str(run_root), str(hermes_home))+ env = dict(os.environ)++ def sh(cmd: str) -> str:+ return subprocess.run(["sh", "-c", cmd], env=env, capture_output=True, text=True, check=True).stdout++ # Touch crontab only once the shim is proven first on PATH, so a regression can never+ # write the host's real crontab from the test itself.+ assert sh("command -v crontab").strip() == str(run_root / "bin" / "crontab")+ assert sh("echo '0 2 * * * ./backup.sh' | crontab - && crontab -l") == "0 2 * * * ./backup.sh\n"+ assert Path(crontab_file).read_text(encoding="utf-8") == "0 2 * * * ./backup.sh\n"+ assert sh('echo "$HOME"').strip() == str(hermes_home / "home")+ assert env["TERMINAL_HOME_MODE"] == "profile"+ assert "DBUS_SESSION_BUS_ADDRESS" not in env and "XDG_RUNTIME_DIR" not in env