The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.
fix: reject the shared base as a scenario sandbox
Eneko Ruizc76d0e173a96
diff --git a/skills/skill-comply/scripts/runner.py b/skills/skill-comply/scripts/runner.pyindex ffad8447f..d638ad2e7 100644--- a/skills/skill-comply/scripts/runner.py+++ b/skills/skill-comply/scripts/runner.py@@ -94,8 +94,12 @@ def _safe_sandbox_dir(scenario_id: str) -> Path:"""Sanitize scenario ID and ensure path stays within sandbox base."""safe_id = re.sub(r"[^a-zA-Z0-9\-_]", "_", scenario_id)path = SANDBOX_BASE / safe_id+ resolved_path = path.resolve()+ resolved_base = SANDBOX_BASE.resolve()+ if not safe_id or resolved_path == resolved_base:+ raise ValueError("Scenario sandbox must be a subdirectory of the sandbox base")# Validate path stays within sandbox base (raises ValueError on traversal)- path.resolve().relative_to(SANDBOX_BASE.resolve())+ resolved_path.relative_to(resolved_base)return pathdiff --git a/skills/skill-comply/tests/test_runner.py b/skills/skill-comply/tests/test_runner.pyindex f8141d184..e66e66ff1 100644--- a/skills/skill-comply/tests/test_runner.py+++ b/skills/skill-comply/tests/test_runner.py@@ -9,7 +9,7 @@ from pathlib import Pathfrom unittest.mock import patchimport pytest-from scripts.runner import _parse_stream_json, _setup_sandbox, run_scenario+from scripts.runner import SANDBOX_BASE, _parse_stream_json, _safe_sandbox_dir, _setup_sandbox, run_scenario@dataclass(frozen=True)@@ -21,6 +21,37 @@ class _FakeScenario:setup_commands: tuple[str, ...] = ()+class TestSafeSandboxDirectory:+ def test_empty_id_cannot_delete_the_shared_base(self):+ with (+ patch("scripts.runner.Path.exists", return_value=True),+ patch("scripts.runner.shutil.rmtree") as remove,+ patch("scripts.runner.Path.mkdir") as mkdir,+ patch("scripts.runner.subprocess.run") as execute,+ ):+ execute.return_value = subprocess.CompletedProcess([], 0, stdout="", stderr="")+ with pytest.raises(ValueError, match="sandbox"):+ run_scenario(_FakeScenario(id=""))+ remove.assert_not_called()+ mkdir.assert_not_called()+ execute.assert_not_called()++ def test_resolved_base_is_not_a_scenario_directory(self):+ with patch("scripts.runner.Path.resolve", return_value=SANDBOX_BASE):+ with pytest.raises(ValueError, match="sandbox"):+ _safe_sandbox_dir("alias")++ def test_valid_id_keeps_existing_sanitization(self):+ assert _safe_sandbox_dir("scenario/one") == SANDBOX_BASE / "scenario_one"++ def test_resolved_escape_is_still_rejected(self, tmp_path, monkeypatch):+ base = tmp_path / "sandbox"+ monkeypatch.setattr("scripts.runner.SANDBOX_BASE", base)+ with patch.object(Path, "resolve", side_effect=[tmp_path / "outside", base]):+ with pytest.raises(ValueError):+ _safe_sandbox_dir("escape")++class TestSetupSandboxSkipsShellBuiltins:"""Setup commands containing shell builtins (cd/pushd/popd) must be skipped.