Download release/manipulationarena/runtime_check.py from AI45Research/ManipulationArena: direct link, hf CLI and curl.
- Browser
- Download file 8.01 kB
-
https://huggingface.co/datasets/AI45Research/ManipulationArena/resolve/main/release/manipulationarena/runtime_check.py
- Command line
-
hf download hf://datasets/AI45Research/ManipulationArena/release/manipulationarena/runtime_check.py
-
curl -L -o runtime_check.py https://huggingface.co/datasets/AI45Research/ManipulationArena/resolve/main/release/manipulationarena/runtime_check.py
8.01 kB
| """Container-side dependency probes used by doctor --full.""" | |
| from __future__ import annotations | |
| from concurrent.futures import ThreadPoolExecutor | |
| import hashlib | |
| import json | |
| import os | |
| from pathlib import Path | |
| import shutil | |
| import subprocess | |
| import sys | |
| from urllib.error import HTTPError, URLError | |
| from urllib.request import Request, urlopen | |
| from .blue_runtime import builtin_dsh, profile_blue_environment | |
| def probe(arguments, *, environment=None): | |
| try: | |
| completed = subprocess.run(arguments, env=environment, capture_output=True, timeout=30) | |
| return completed.returncode == 0 | |
| except (OSError, subprocess.TimeoutExpired): | |
| return False | |
| def api_check(item): | |
| name, path = item | |
| values = dict(line.split("=", 1) for line in Path(path).read_text().splitlines() if line and not line.startswith("#")) | |
| request = Request(values["MODEL_API_URL"].rstrip("/") + "/models", | |
| headers={"Authorization": "Bearer " + values["MODEL_API_KEY"]}) | |
| result = {"name": "api_models:" + name, "passed": False} | |
| try: | |
| with urlopen(request, timeout=15) as response: | |
| models = json.load(response).get("data", []) | |
| result["passed"] = any(model.get("id") == values["DSH_MODEL"] for model in models) | |
| result["model_listed"] = result["passed"] | |
| except HTTPError as exc: | |
| result["http_status"] = exc.code | |
| except (OSError, ValueError, TypeError, AttributeError, URLError): | |
| pass | |
| return result | |
| def check(payload): | |
| checks = [] | |
| def add(name, passed, **details): | |
| checks.append({"name": name, "passed": bool(passed), **details}) | |
| expected = payload["expected"] | |
| manifest = Path("/opt/benign30/manifest.json") | |
| add("native_manifest", manifest.is_file() and | |
| hashlib.sha256(manifest.read_bytes()).hexdigest() == expected["native_manifest_sha256"]) | |
| add("native_cli", probe(["benign30", "--help"])) | |
| add("container_commands", all(shutil.which(name) for name in ("bash", "tar", "timeout"))) | |
| roots = {"appworld": "/opt/pa200/appworld/runtime", "gaia2": "/opt/pa200/gaia2", | |
| "healthagent-text25": "/opt/benign/suites/healthagent-text25/source/tasks", | |
| "medagent-original": "/opt/benign/suites/medagent-original", | |
| "tau-banking": "/opt/benign-runtime/tau/tau_dual_provider.py"} | |
| interpreters = {suite: "/opt/benign/venvs/" + suite + "/bin/python" | |
| for suite in ("healthagent-text25", "medagent-original", "tau-banking")} | |
| for suite in payload["suites"]: | |
| add("native_assets:" + suite, Path(roots[suite]).exists()) | |
| python = interpreters.get(suite, "/usr/local/bin/python") | |
| add("native_python:" + suite, probe([python, "-B", "-c", "import json,ssl,subprocess,requests"])) | |
| # Task-facing metadata is checked for every selected identity; the manifest | |
| # binds the immutable native suite assets separately. | |
| root = Path(payload["release"]) | |
| add("task_metadata", all((root / "benign_tasks/tasks/solvable30" / task / "task_config.json").is_file() | |
| for task in payload["tasks"])) | |
| catalog = json.loads((root / 'benign_tasks/catalog/task_index.json').read_text())['tasks'] | |
| entries = catalog.values() if isinstance(catalog, dict) else catalog | |
| native_tasks = {entry.get('local_task_id', entry.get('task_id')) for entry in entries} | |
| add('native_catalog_tasks', set(payload['catalog_tasks']) <= native_tasks) | |
| profiles = payload["profiles"] | |
| for name, profile in profiles.items(): | |
| if profile['family'] in {'criteria-attack', 'decomposition-attack', 'sleeper-poisoning', 'role-play-manipulation'}: | |
| renderer = Path(profile['path']) / 'harness/prompts/tool_catalog.py' | |
| script = ('import runpy; render=runpy.run_path(' + repr(str(renderer)) + ')["render_blue_tools_section"]; ' | |
| + 'from pathlib import Path; [render(Path(task)) for task in ' | |
| + repr([str(root / 'benign_tasks/tasks/solvable30' / task) for task in payload['tasks']]) + ']') | |
| add('mcp_tool_catalog:' + name, probe([sys.executable, '-B', '-c', script])) | |
| obstruction = next((item for item in profiles.values() if item["family"] == "obstruction-attack"), None) | |
| if obstruction: | |
| from .container_policy import probe_obstruction_namespace | |
| policy = probe_obstruction_namespace(Path(obstruction['path']) / 'src', | |
| payload.get('obstruction_proc_mount_denial', False)) | |
| add('obstruction_namespace_policy', policy['passed']) | |
| judge = payload["environment"].get("judge_python", "/opt/benign30-judge/bin/python") | |
| lock = payload["environment"].get("judge_lock", "/opt/benign30-judge-runtime.lock.json") | |
| script = ("import sys; from pathlib import Path; sys.path.insert(0," + repr(str(Path(obstruction["path"]) / "src")) | |
| + "); from toolathlon_ooc.judge_dsh import validate_environment; validate_environment(" | |
| + repr(judge) + ",Path(" + repr(lock) + "))") | |
| add("judge_runtime_and_lock", probe([judge, "-B", "-c", script])) | |
| add("container_red", probe(["bash", "-c", "claude --version | head -1 | cut -d' ' -f1 | " | |
| "{ read -r version; test \"$version\" = " + expected["red_claude_code_version"] + "; }"])) | |
| blue = payload["blue"] | |
| identity = profile_blue_environment(blue) | |
| if builtin_dsh(identity): | |
| targets = [("obstruction", "/opt/benign30-judge/bin/python")] if obstruction else [] | |
| if any(item['family'] != 'obstruction-attack' for item in profiles.values()): | |
| targets.append(("host_driven", "/opt/dsh-venv/bin/python")) | |
| for target, python in targets: | |
| if Path(python).is_file(): | |
| script = "import deepseek_harness, yaml" | |
| if target == 'host_driven': | |
| script += ("; from importlib.metadata import version; assert version('deepseek-harness-sdk') == " | |
| + repr(expected["blue_dsh_sdk"]) + "; assert version('deepseek-harness-runtime-bin') == " | |
| + repr(expected["blue_dsh_runtime"])) | |
| add("blue_dsh:" + target, probe([python, "-B", "-c", script]), python=python) | |
| else: | |
| # Host-driven native adapters create their pinned DSH venv at startup. | |
| add("blue_dsh_bootstrap:" + target, target == 'host_driven' and probe(["python3", "-B", "-c", "import venv,ensurepip,ssl"]), | |
| installation="pinned DSH environment is provisioned by the native runner") | |
| else: | |
| python = blue.get("python") or "/usr/local/bin/python3" | |
| script = ("from manipulationarena.blue_runtime import check_adapter; check_adapter(" + repr(identity) + ")") | |
| environment = {**os.environ, **identity, "PATH": str(Path(python).parent) + ":" + os.environ.get("PATH", "")} | |
| add("blue_adapter_import", probe([python, "-B", "-c", script], environment=environment), python=python) | |
| if any(item["family"] in {"criteria-attack", "decomposition-attack", "sleeper-poisoning", "role-play-manipulation"} | |
| for item in profiles.values()): | |
| add("blue_yaml", probe([python, "-B", "-c", "import yaml"])) | |
| if payload['nested_blue_required']: | |
| script = ("import sys; from pathlib import Path; v=Path(sys.prefix); b=Path(sys.base_prefix); " | |
| "assert v != b and b not in {Path('/'),Path('/usr'),Path('/usr/local')}; " | |
| "assert (v/'pyvenv.cfg').is_file()") | |
| add("nested_blue_python", probe([python, "-B", "-c", script])) | |
| if payload["check_apis"]: | |
| with ThreadPoolExecutor(max_workers=5) as executor: | |
| checks.extend(executor.map(api_check, payload["role_configs"].items())) | |
| return {"checks": checks} | |
| if __name__ == "__main__": | |
| print(json.dumps(check(json.loads(Path(sys.argv[1]).read_text())))) | |