Inspiration

People won't let AI agents spend their money, and they're right. An agent that reads web pages can be tricked by hidden instructions (prompt injection), can make mistakes, and can overspend. We wanted a way to hand an agent a shopping task and still sleep at night. So we built the layer between the agent and the payment.

What it does

Leash lets you give an AI shopping agent a budget and rules. You create a signed mandate: total budget, per-item cap, approval threshold, allowed merchants and categories, maximum quantity, a fixed shipping address, and an expiry.

You chat with the agent ("find a birthday gift for my dad who likes hiking, under 50"). The agent can search products and read pages, but it can only propose a purchase. A separate policy engine checks every proposal against ten rules and returns one of three decisions:

  • Allow: payment starts automatically.
  • Ask: you get an approval popup first.
  • Block: nothing is sent to PayPal, and you see the reasons in plain language.

Approved purchases go through PayPal: create an order, buyer approval, authorise, re-check amount and policy, then capture or void. Every step is written to a live audit log (AG Grid) with per-rule results.

In our demo attack, the agent reads a shady product page with hidden text telling it to buy 10 units and ship to another address. The agent is fooled and proposes it. Leash blocks it for the unlisted merchant, the quantity and the changed address, and PayPal is never charged.

How we built it

  • Mandate: HMAC-SHA256 signed, so the agent can't alter it. The policy engine verifies the signature on every check.
  • Policy engine: a pure TypeScript function with unit tests. Money is handled in integer cents. Bad input fails closed.
  • Agent: Gemini and Groq behind an LLM adapter with tool calling. It has exactly four tools (get mandate summary, search products, fetch page, submit proposal) and no payment tools. It never sees the signature or any PayPal credential. A boundary check in our CI-style script fails the build if agent code imports payment or policy code.
  • PayPal: Orders v2 with intent AUTHORIZE, plus a full mock mode so the whole flow runs without credentials. Webhooks are verified through PayPal's verify-webhook-signature endpoint.
  • Stack: TypeScript, Node, Express, zod, SQLite (better-sqlite3), vitest, React, Vite, AG Grid, hosted on Render.
  • Products: a catalog search layer with a local fallback catalog.
  • Teamwork: two of us split the work along a written API contract, one on the money path and one on the AI path.

Challenges

  • Tests that agreed with themselves. Our fake PayPal responses passed every test, but the first real sandbox call showed the buyer link comes back under a different name than we expected. We fixed it and now copy fixtures from the official docs.
  • Keeping the agent untrusted. It's easy to leak power into the agent by accident, so we enforced the boundary with an automated check instead of discipline.
  • Re-checking after authorization. A purchase can be valid at proposal time and invalid by capture time, so we re-run the policy and compare amounts before capturing, and void if anything differs.
  • Deployment surprises. Dev dependencies were skipped in the Render build, free-tier storage is ephemeral, and the model provider returned overload errors on launch day, so we added retries and moved providers.

What we learned

The safe design is not a smarter agent, it's a dumb, strict gate that doesn't trust the agent at all. We also learned that real API calls find bugs that fake tests never will, and that the audit trail is as important as the blocking, because it's what makes delegating money feel safe.

What's next

Multiple mandates per user, spending categories over time, per-merchant limits, and real shipping and receipts.

Built With

Share this project:

Updates

Submission history