Inspiration

AI agents are becoming capable of researching products, making decisions and carrying out tasks on our behalf. But giving an agent access to money also creates a problem: what happens if it makes the wrong purchase, gets manipulated, or goes beyond what the user intended?

We wanted to explore how people could let AI agents handle shopping without giving them unrestricted control over payments.

What we built

We built Leash, a spending gateway that sits between an AI shopping agent and PayPal.

The user creates a spending mandate that defines a monthly budget, maximum order value, approval threshold, permitted categories and other restrictions. The mandate is signed using an Ed25519 key in the owner's browser.

The AI agent can search the product catalog and propose purchases, but it does not get payment credentials. Before a purchase can proceed, the gateway independently checks it against the signed mandate.

Requests can be allowed, held for human approval, or blocked. The gateway also records decisions in a hash-chained audit ledger.

The project includes a live AI shopping agent using Gemini with Groq as a fallback, along with a Red Team simulation that tests six scenarios, including prompt injection through product descriptions, cart tampering, gift-card scams, replayed requests and concurrent purchase attempts.

We integrated PayPal Sandbox to demonstrate buyer-approved payment authorization, partial captures, idempotent retries and voiding the remaining authorization. No real money is involved.

How we built it

We used TypeScript across the project, with React for the owner console, Fastify for the gateway API and PostgreSQL for storing decisions, payment records and the audit ledger.

The core package handles mandate validation, Ed25519 signatures, policy checks and ledger hashing. The gateway handles payment operations and webhook reconciliation, while the agent communicates with it through HTTP.

The application is deployed using Render and Neon PostgreSQL.

Challenges we faced

One of the biggest challenges was working with PayPal's sandbox APIs. We initially explored PayPal Vault for saved payment methods, but our sandbox merchant account was not enabled for the required Vault functionality. We therefore implemented and tested an alternative buyer-approved authorization flow with partial captures.

We also had to think carefully about security boundaries. An AI model should not be trusted to enforce its own spending limits, so we made the gateway's deterministic policy engine responsible for the final decision.

Another challenge was handling concurrent purchase attempts and preventing duplicate payments. We addressed this with gateway-side checks, database locking and PayPal request idempotency.

What we learned

Building Leash helped us understand that making an AI agent capable of taking actions is only one part of the problem. It is equally important to define what it is allowed to do, enforce those limits outside the model, and keep a record of every important action.

Our goal with Leash is simple: let AI agents do useful work without handing them unrestricted control over money.

Built With

Share this project:

Updates

Submission history