File size: 1,032 Bytes
04ae9bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""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)]