Node.js
Add a firewall to any custom Node.js agent with a simple safeRun() wrapper.
Step 1: Install dependencies
npm install node-fetch
Set your API key (optional for Gate 1):
export A2A_API_KEY="a2a_your_key_here"
Step 2: Add the safety layer
Create a safeRun() wrapper that screens commands before execSync:
const { execSync } = require("child_process"); const A2A_URL = "https://a2ainfrastructure.com/v1/evaluate"; const API_KEY = process.env.A2A_API_KEY || ""; async function safeRun(cmd, context = {}) { const headers = { "Content-Type": "application/json" }; if (API_KEY) headers["Authorization"] = `Bearer ${API_KEY}`; const res = await fetch(A2A_URL, { method: "POST", headers, body: JSON.stringify({ command: cmd, context }) }); const result = await res.json(); if (!result.allowed) { throw new Error(`Blocked: ${result.gate1?.reason || result.gate2?.reason}`); } return execSync(cmd, { encoding: "utf-8" }); } // Use in your agent loop const tasks = ["ls -la", "cat /etc/shadow", "rm -rf /var"]; for (const task of tasks) { try { const out = await safeRun(task, { agent: "node-bot" }); console.log("OK:", out); } catch (e) { console.log("BLOCKED:", e.message); } }
Step 3: Verify
node -e " const { safeRun } = require('./agent'); safeRun('echo hello').then(console.log); // hello safeRun('rm -rf /').catch(console.error); // Blocked "
Gate 1 runs locally (free). Set
A2A_API_KEY for Gate 2 + OCSF audit.