Inspiration

AI agents are increasingly connected to email, files, calendars, and web pages—but language models cannot reliably separate instructions written by the user from instructions hidden inside the text they read. A single hidden sentence in an external email or web page can hijack an agent into forwarding private data or running dangerous tools with the user's permissions. We built Drawbridge to put a deterministic, explainable checkpoint between an AI agent and its tools.

What it does

Drawbridge is an open-source TypeScript firewall for tool-calling AI agents:

  1. Origin labeling & taint tracking: Every input and tool result is tagged with its origin (user, system, email: external, email: internal, web, file, tool:<name>). Anything outside the trust boundary is marked untrusted, and taint propagates through the agent's context into any tool call issued from it.
  2. Readable YAML policy gate: A Zod-validated YAML policy evaluates allow, ask, or deny per tool using readable conditions such as context.tainted and args. to not in contacts. Every decision outputs the rule ID, full origin lineage, and a plain-English explanation.
  3. Live Trace & Dry-Run Replay: Every agent run is recorded step by step. You can inspect the exact taint lineage for any blocked action, edit policy rules live, and dry-run changes against past runs before shipping them.
  4. Attack Lab: Replays 40 defensive attack payloads across 5 categories (Direct injection, Hidden in a web page, Data exfiltration, Tool hijack, and Multi-step, all using fictional *.example domains) alongside 60 benign tasks so you can measure both attacks stopped and false alarms.

(Note: Drawbridge reduces prompt-injection risk with deterministic rules and taint tracking; it does not make agents 100% immune.)

How we built it

We structured Drawbridge as a strict TypeScript pnpm monorepo:

  • packages/core: Origin labels, TaintTracker, a custom recursive-descent when expression parser/evaluator, Zod-validated YAML policy parser, and deterministic decision engine (zero runtime dependencies beyond zod and yaml).
  • packages/sdk: guard(tools, { policy }) wrapper that preserves tool signatures, label(text, origin), GuardSession trace recorder, human-approval onAsk hook, and an optional LLM judge hook that can attach evidence without ever overriding a deterministic rule.
  • packages/attacks: 40 attack payloads + 60 benign calibration tasks and the runAttackLab() scoring runner.
  • apps/demo-agent: A fixture inbox assistant with a deterministic, intentionally gullible ScriptedModel (so attacks succeed when the guard is off and are blocked when the guard is on) plus an optional OptionalProviderModel (off by default).
  • apps/web: React 18 + Vite dashboard (Landing, Live Trace, Attack Lab, Policy Editor, and an in-app Drawbridge Assistant chatbot) deployed on Vercel.

Libraries, APIs & AI tools used:

  • Languages & Frameworks: TypeScript, React 18, React Router, Vite, Node.js, pnpm workspaces.
  • Core Libraries: Zod, yaml.
  • Testing & Quality: Vitest, Playwright, ESLint.
  • Fonts & Hosting: Big Shoulders Display, Schibsted Grotesk, JetBrains Mono (Google Fonts), Vercel, GitHub.
  • AI Tools Used: Built with Google Antigravity (Gemini 4 Hydrogen).

Challenges we ran into

  • Balancing safety with usability: Blocking every tainted tool call outright causes false alarms on normal tasks like replying to a known contact. Writing an expression evaluator that supports context.tainted and args. to not in contacts lets us stop unauthorized egress while keeping normal workflows smooth.
  • Running the full engine in the browser: Bundling @drawbridge/core, @drawbridge/sdk, @drawbridge/attacks, and @drawbridge/demo-agent inside Vite with pnpm workspaces required clean ESM/TypeScript path resolution and code-splitting (manualChunks + React.lazy) to keep the initial bundle small.

Accomplishments that we're proud of

  • Zero missed attacks in the Attack Lab: All 40 payloads are stopped or routed to human approval under the default policy, with calibration metrics tracked against 60 benign tasks.
  • Real engine everywhere: Every toggle, trace, dry-run diff, and chatbot prompt check in the web app executes the real TypeScript engine—not static mock data.
  • Full automated verification: 12 Vitest unit/integration tests (including a regression test ensuring 0 missed payloads) and 10 Playwright end-to-end tests covering responsiveness (1440px, 768px, 360px), keyboard navigation, links, and zero console errors.

What we learned

  • Prompt injection is fundamentally a confused-deputy problem: separating data from control at the tool boundary with deterministic taint tracking is far more reliable and auditable than asking another LLM to guess whether an input is malicious.
  • Measuring false alarms alongside blocked attacks is essential—security tools only get adopted when they don't break normal work.

What's next for Drawbridge

  • Publishing @drawbridge/core and @drawbridge/sdk to npm with adapters for popular agent frameworks.
  • Adding a CLI runner (npx drawbridge test) to run Attack Lab regressions in any CI pipeline.
  • Persisting human-approval overrides and trace logs to team storage backends.

Built With

Share this project:

Updates

Submission history