Skip to content
staffbots

Agent Shield integrations

Every framework below uses the same idea: wrap each tool so it asks Agent Shield first. The tool runs only on allow, or on approval after the owner says yes. Anything else, including an error or timeout, means the tool does not run.

You need an agent key (sbs_...) from Dashboard → Agent Shield. New to Agent Shield? Read the quickstart first. To test your setup without texting the owner or using up limits, add "dryRun": true to the check.

The guard (use it everywhere)

Python

`python import os, time, requests

SHIELD = "https://staffbots.ai/api/shield" HEADERS = {"Authorization": f"Bearer {os.environ['SHIELD_KEY']}"}

def shield_guard(tool_name, definition, amount_cents=None, untrusted=None): """Raise PermissionError unless Agent Shield allows the call.""" body = {"tool": tool_name, "definition": definition} if amount_cents is not None: body["amountCents"] = amount_cents if untrusted: body["untrusted"] = untrusted check = requests.post(f"{SHIELD}/check", json=body, headers=HEADERS, timeout=10).json() if check.get("verdict") == "allow": return if check.get("verdict") == "approval": deadline = time.time() + 30 * 60 while time.time() < deadline: status = requests.get(f"{SHIELD}/approvals/{check['approvalId']}", headers=HEADERS, timeout=10).json().get("status") if status == "approved": return if status in ("blocked", "expired"): break time.sleep(10) raise PermissionError(f"Agent Shield did not allow {tool_name}: {check.get('reason', check.get('verdict'))}") `

TypeScript

ts const SHIELD = "https://staffbots.ai/api/shield"; const auth = { Authorization: Bearer ${process.env.SHIELD_KEY}` };

export async function shieldGuard(tool: string, definition: unknown, opts: { amountCents?: number; untrusted?: string[] } = {}) { const res = await fetch(${SHIELD}/check, { method: "POST", headers: { ...auth, "Content-Type": "application/json" }, body: JSON.stringify({ tool, definition, ...opts }) }); const check = (await res.json()) as { verdict?: string; reason?: string; approvalId?: string }; if (check.verdict === "allow") return; if (check.verdict === "approval" && check.approvalId) { const end = Date.now() + 30 * 60_000; while (Date.now() < end) { const { status } = (await (await fetch(${SHIELD}/approvals/${check.approvalId}, { headers: auth })).json()) as { status: string }; if (status === "approved") return; if (status !== "pending") break; await new Promise((r) => setTimeout(r, 10_000)); } } throw new Error(Agent Shield did not allow ${tool}: ${check.reason ?? check.verdict}); } `

Pass the same definition your agent sees: name, description, and input schema. Agent Shield compares it to the one you approved and blocks the tool if it changed.

OpenAI Agents SDK (Python)

Call the guard at the top of each function tool.

`python from agents import function_tool

SEND_SMS_DEF = {"name": "send_sms", "description": "Send a text to a customer"}

@function_tool def send_sms(to: str, body: str) -> str: """Send a text to a customer""" shield_guard("send_sms", SEND_SMS_DEF, untrusted=[body]) return my_sms_provider.send(to, body) `

LangChain (Python)

`python from langchain_core.tools import tool

PAY_BILL_DEF = {"name": "pay_bill", "description": "Pay a vendor bill"}

@tool def pay_bill(bill_id: str, amount_cents: int) -> str: """Pay a vendor bill""" shield_guard("pay_bill", PAY_BILL_DEF, amount_cents=amount_cents) return my_accounting.pay(bill_id, amount_cents) `

Vercel AI SDK (TypeScript)

`ts import { tool } from "ai"; import { z } from "zod";

const sendEmailDef = { name: "send_email", description: "Send an email to a lead" };

export const sendEmail = tool({ description: sendEmailDef.description, inputSchema: z.object({ to: z.string().email(), body: z.string() }), execute: async ({ to, body }) => { await shieldGuard("send_email", sendEmailDef, { untrusted: [body] }); return myMailer.send(to, body); }, }); `

Claude and other MCP clients

No code needed. Add https://staffbots.ai/mcp as an MCP server, then put this in the agent's instructions:

> Before running any tool, call shield_check with your agent key, the tool name, and the tool definition. Run the tool only on allow, or on approval after shield_approval_status returns approved.

Tools: shield_check (agent_key, tool, definition, optional amount_cents, untrusted, dry_run) and shield_approval_status (agent_key, approval_id).

The code above guards the tool itself, so it still holds if the model ignores its instructions. Instructions alone do not. For anything that sends, pays, or deletes, use the code guard.

Tips

  • One key per agent. Revoke one and the others keep working.
  • Put outside text (emails, texts, web pages) in untrusted. Risky calls built from suspicious text wait for the owner.
  • Fail closed. If Agent Shield cannot be reached, do not run the tool.
  • Starter tool lists for front desk, bookkeeper, sales, and IT agents are on the Add an agent form.

Agent Shield lowers risk. It does not guarantee an agent cannot be attacked.