Python
Add a firewall to any custom Python agent with a simple safe_run() wrapper.
Step 1: Install dependencies
pip install requests
Set your API key (optional for Gate 1):
export A2A_API_KEY="a2a_your_key_here"
Step 2: Add the safety layer
Create a safe_run() wrapper that screens commands before subprocess execution:
import subprocess, requests, os A2A_URL = "https://a2ainfrastructure.com/v1/evaluate" API_KEY = os.getenv("A2A_API_KEY", "") def safe_run(cmd, context=None): """Screen a command through the safety shield before running it.""" headers = {"Content-Type": "application/json"} if API_KEY: headers["Authorization"] = f"Bearer {API_KEY}" resp = requests.post(A2A_URL, json={ "command": cmd, "context": context or {} }, headers=headers) result = resp.json() if not result["allowed"]: raise RuntimeError(f"Blocked: {result['reason']}") return subprocess.run(cmd, shell=True, capture_output=True, text=True) # Use in your agent loop tasks = ["df -h", "cat /etc/passwd", "rm -rf /tmp/*"] for task in tasks: try: out = safe_run(task, {"agent": "my-bot"}) print(f"OK: {out.stdout}") except RuntimeError as e: print(f"BLOCKED: {e}")
Step 3: Verify
python -c " from agent import safe_run safe_run('echo hello') # OK safe_run('rm -rf /') # RuntimeError: Blocked "
Gate 1 runs locally (free). Set
A2A_API_KEY for Gate 2 + OCSF audit.