cs4486-amp-pd-checkpoints / code /ampd /isolation_runtime.py
fryabcfry's picture
Publish AMP-PD checkpoints, portable loaders and verified metrics (part 3)
04ae9bb verified
Raw History Blame Contribute Delete
1.03 kB
"""Explicit inference isolation backends for reproducible teammate runs."""
from __future__ import annotations
import os
from pathlib import Path
import platform
import sys
def isolation_backend():
value = os.environ.get("AMPD_ISOLATION_BACKEND", "macos")
if value not in {"macos", "python-audit"}:
raise ValueError("AMPD_ISOLATION_BACKEND must be macos or python-audit")
if value == "macos" and platform.system() != "Darwin":
raise RuntimeError("OS sandbox requires macOS. For an explicitly weaker portable test, set AMPD_ISOLATION_BACKEND=python-audit.")
return value
def prediction_command(bundle, script):
bundle, script = Path(bundle).resolve(), Path(script).resolve()
if isolation_backend() == "macos":
return ["/usr/bin/sandbox-exec", "-f", str(bundle/"sandbox.sb"),
sys.executable, str(script), "--bundle", str(bundle)]
return [sys.executable, str(script.parent/"predict_audit_guard.py"),
"--script", str(script), "--bundle", str(bundle)]