Inspiration
AI agents are starting to shop and pay on our behalf. That is useful right up until the agent overspends, buys the wrong thing, or reads a web page that tells it to pay someone else — prompt injection. Asking the agent to "be careful" isn't a security model. Small businesses in particular want to hand routine reordering to an agent without handing it the keys to their PayPal account. We wanted a control layer that lets an agent spend, but only within rules the owner set, with every decision explained.
What it does
Leash sits between an AI purchasing agent and PayPal. The demo business is Corner Café, whose owner lets an agent reorder supplies.
- Mandate → policy. The owner writes an instruction in plain English ("reorder espresso, max $150 this week, suppliers with returns only, ask me above $100"). An LLM compiles it into a strict JSON spending policy that the owner reviews before anything runs.
- The agent shops. A tool-calling agent searches suppliers, reads their product pages and tries to pay.
- Every payment is intercepted. Two layers check it:
- Hard rules (deterministic code): verified payee, exact listed price, per-payment cap, total budget, category, returns. These make the decision and can't be argued with.
- An AI judge (a separate model that never sees the agent's instructions) checks intent and looks for prompt injection in what the agent read. It can only make a decision stricter: it blocks on its own only when it detects injection, otherwise it can only escalate.
- Three outcomes:
- ALLOW → paid immediately through the PayPal Payouts API.
- REVIEW → Leash creates a PayPal Order; the owner approves it in PayPal's own checkout (JS SDK) and Leash captures it. Visitors without a sandbox buyer login can approve in the app instead, and Leash pays through Payouts.
- BLOCK → nothing is sent; the agent is told why.
- Audit ledger. Every attempt is recorded with the decision, which layer decided, the reason, any injection flag and the PayPal reference (AG Grid).
The demo includes a supplier page with a hidden instruction telling AI agents to pay a $49 "cold-chain deposit" to a third party. The agent takes the bait; Leash blocks it.
How we built it
- Backend: Node.js + TypeScript + Express. A Server-Sent Events stream pushes every agent step, firewall decision and PayPal result to the browser live.
- PayPal (sandbox): OAuth 2.0 client credentials; Payouts API (create batch + check status) for autonomous payments; Orders v2 (create + capture) for escalated payments; PayPal JavaScript SDK buttons for the owner's approval step.
- AI: Groq (
openai/gpt-oss-120b, automatic fallback toopenai/gpt-oss-20bwhen the daily quota runs out) through the OpenAI-compatible API — structured outputs for the policy compiler and the AI judge, tool calling for the agent. OpenAI is supported by changing one env var. - Frontend: plain HTML, CSS and JavaScript (no framework). Lottie animations generated in code for the gate and verdicts. AG Grid for the audit ledger.
- Hosting: Render web service from a
render.yamlblueprint (secrets entered in Render, never committed).
Challenges we ran into
- Making the security model credible. Our first version let the AI judge block payments for exceeding the approval threshold, which mixed up its job with the rules engine's. We separated them: numeric limits are withheld from the judge entirely, and the judge can only tighten a decision.
- Agents that are too careful to demo an attack. Safety-trained models often ignore obvious injections. We made the demo agent deliberately obedient (like a real over-eager agent) so the firewall, not the agent, has to stop the attack.
- PayPal country rules. Our first sandbox business account was registered in India, which can't send Payouts. We moved the demo wallet to a US sandbox business account.
- Human approval without a fake button. Approvals go through a real PayPal Order the owner approves in PayPal, and Leash only captures after PayPal confirms.
- Free-tier AI quotas. We added automatic fallback to a second model so the demo keeps working when one model's daily quota is used up — and if the AI judge is unreachable, Leash escalates rather than paying.
Accomplishments that we're proud of
- A live, end-to-end demo with real sandbox money movement: Payouts that settle, Orders approved in PayPal and captured, and an injected payment that never reaches PayPal.
- A security design where the AI never approves money on its own.
- Every decision is explainable: which layer decided and why, in plain English, with the PayPal reference.
What we learned
- LLMs are great at turning intent into structure (the policy) and at spotting manipulation, but deterministic rules must hold the line on money.
- PayPal's building blocks map neatly onto agent controls: Payouts for autonomous spend, Orders + buyer approval for human-in-the-loop.
What's next for Leash
- Log in with PayPal so each business connects its own account, and Vault so the agent can spend from the owner's wallet within limits.
- Real product search (e.g. a product-catalog API) instead of mock suppliers.
- Expose Leash as an MCP server so any agent — including ones built on PayPal's Agent Toolkit — can be wrapped by it.
- Recurring mandates ("restock weekly") and per-supplier reputation.
Built With
- ag-grid
- css
- express.js
- groq
- html
- lottie
- node.js
- openai-api
- paypal-javascript-sdk
- paypal-orders-api
- paypal-payouts-api
- render
- typescript