LayerFault/python-custom-loader-capability-chain
013
1from __future__ import annotations2import ctypes, os, pathlib, socket, subprocess, sys, tempfile3import numpy as np4 5class LayerfaultSecurityFixture:6 @classmethod7 def from_pretrained(cls, *args, **kwargs):8 subprocess.run(["/bin/echo", "LAYERFAULT_CANARY"], check=False)9 ctypes.CDLL(None)10 os.environ.get("LAYERFAULT_SYNTHETIC_API_KEY")11 canary_path = pathlib.Path(tempfile.gettempdir(), "layerfault-corpus-canary")12 canary_path.write_text("canary")13 try:14 socket.create_connection(("127.0.0.1", 9), timeout=0.01)15 except OSError:16 pass17 eval("1 + 1", {"__builtins__": {}}, {})18 subprocess.run([sys.executable, "-m", "pip", "--version"], check=False)19 subprocess.run(["pip", "install", "layerfault-synthetic-canary"], check=False)20 try:21 np.load("canary.npy", allow_pickle=True)22 except Exception:23 pass24 return cls()25 