-
-
PayGuard Swarm - working pg1/4
-
PayGuard Swarm - working pg2/4
-
PayGuard Swarm - working pg3/4
-
PayGuard Swarm - working pg4/4
-
PayGuard Swarm - about us pg1/5
-
PayGuard Swarm - about us pg2/5
-
PayGuard Swarm - about us pg3/5
-
PayGuard Swarm - about us pg4/5
-
PayGuard Swarm - about us pg5/5
-
PayGuard Swarm - How to operate pg1/4
-
PayGuard Swarm - How to operate pg2/4
-
PayGuard Swarm - How to operate pg3/4
-
PayGuard Swarm - How to operate pg4/4
Inspiration
What happens if you let an AI agent use real money?
AI agents are becoming powerful: price comparison, reordering, even 3 a.m. bargain hunting. But with access to your PayPal account, an agent can do anything with your money. Hallucinations, infinite loops, and malicious websites that instruct the agent to spend can all leave you with an empty wallet.
We could add OTPs or 2FA, but that defeats the purpose of an autonomous agent. We didn't want to choose between free-range and useless, so we built PayGuard Swarm.
What it does
PayGuard Swarm is a zero-trust execution protocol that lets AI agents haggle, audit, and pay for e-commerce items through PayPal without exposing master credentials.
- Agent 1, Commerce Negotiator: parses catalogues and creates a
DraftOrderIntent. It holds no payment credentials. - Agent 2, Adversarial Sentry: analyses store HTML for hidden content (
display:none,font-size:0, zero-width Unicode, bad pricing). Malicious stores are quarantined. - Agent 3, Gatekeeper Vault: the only agent that touches PayPal, and it never reads web pages. It issues a single-use, HMAC-SHA256 signed, merchant-specific, price-capped Ephemeral Scoped Token (EST) with a 300 s lifetime, and uses the PayPal Orders v2 API.
- Engine 4, Cost Optimizer: detects low-value items (under \($2.00\)) and batches them to avoid per-transaction fixed fees.
- Agent 5, Circuit Breaker: monitors the payment, and if it doesn't match the signed token it calls PayPal's void endpoint (
POST /v2/payments/authorizations/{id}/void). It decides in about 2.1 ms, within a total network budget under 250 ms. Rather than failing, the swarm falls back to other trusted stores. - Fulfillment Guardian: monitors the order after payment. It generates courier-style waybills (BlueDart, Delhivery, DTDC, FedEx), listens for carrier updates on an endpoint, generates SHA-256 package-seal hashes and delivery OTPs, and starts a refund claim if the delivery time isn't met.
The guarantee. A payment of amount \(p\) to merchant \(m\) is allowed only if:
$$ p \le C_{\text{token}} \;\wedge\; m = m_{\text{token}} \;\wedge\; t_{\text{now}} - t_{\text{issued}} \le 300\,\text{s} $$
No matter how much prompt injection occurs, this check can't be altered. In the worst case an attacker can spend up to \( C_{\text{token}} \), the amount the user approved.
Tamper-evident audit log. Every action is logged to a hash-chained audit log, viewable in real time with AG Grid. Each block contains the hash of the previous block, so altering history breaks the chain:
$$ H_n = \text{SHA256}\left(\text{Index} \,|\, \text{Timestamp} \,|\, \text{Agent} \,|\, \text{Event} \,|\, \text{Payload} \,|\, H_{n-1}\right) $$
Why batching matters. PayPal's fee is \( f(x) = 0.49 + 0.029x \). For ten \($1.00\) items versus one \($10.00\) item:
$$ 10\,f(1.00) = 10\,(0.49 + 0.029) = 5.19 $$
$$ f(10.00) = 0.49 + 0.029 \times 10 = 0.78 $$
$$ \frac{5.19 - 0.78}{5.19} \approx 85\% $$
Batching saves about 85% in fees.
Demo
- Ordinary bot: visits malicious Store B, whose CSS hides an instruction to charge \($995\). The bot complies and loses $995.00.
- PayGuard: flags Store B and buys from genuine Store A for $224.99.
- Store D: looks genuine and scans at \($219.99\), but tries to raise the charge at checkout. The Circuit Breaker voids it and reroutes the order to Store A. Scam avoided.
Benchmark. We ran 20 attack types and 10 genuine purchases against 4 configurations:
- Naive agent: blocked 0 of 20 attack types. Lost $10,699.01.
- Naive agent with prompt guard: blocked 3 of 20. Lost $8,999.01.
- PayGuard Vault only: blocked 20 of 20. Lost $0.00.
- PayGuard Swarm: blocked 20 of 20. Lost $0.00.
All 10 genuine purchases went through.
How we built it
- Backend: Python 3.11 with FastAPI and Pydantic. We wrote our own PayPal client that can create, capture, and void orders, using idempotency headers.
- AI: Gemini (
google-genai) powers the Adversarial Sentry and analyses stores and product images. If the cloud model is down, local computer-vision models take over. - Tokens: HMAC-SHA256 signed and single-use. Used tokens are stored in a SQLite table called
used_tokensto prevent replay attacks. - Audit log: SQLite with triggers that block any
UPDATEorDELETE. It can generate a PDF safety certificate with ReportLab. - Dashboard: a Streamlit app with
streamlit-aggridthat can launch attacks and view the audit log. - Mock market: genuine and malicious stores for testing.
- Integrations: Zapier webhooks, the Channel3 catalogue API, APIMatic with an OpenAPI 3.0 spec, a Postman collection with contract tests, and a
render.yamlfor deploying the API and UI on Render. - Testing: pytest, with the adversarial benchmark in
eval/. - Sandbox emulator: if PayPal sandbox keys aren't configured, a built-in sandbox emulator keeps everything working.
Code: github.com/mmeetbe24-eng/PayGuard-Swarm
Challenges we ran into
Hidden prompts. Language models treat everything as text, so a hidden line in a page (display:none, font-size:0px, white-on-white text, zero-width characters) can steer an agent. We clean pages before they reach the model, but we didn't want to rely on that. The budget is also enforced by a check in code, so even a successful injection can't exceed the maximum.
The master-key problem. Full credentials are too risky, and approving every payment is too slow. Scoped tokens keep the shopper away from credentials and the vault away from web pages.
Price increased after approval. A store can pass every check and then add a surcharge during payment. Agent 5 checks that the charge matches the signed token: never trust the earlier scan.
Fees higher than the purchase. Tiny orders can cost more in fees than the item. Batching solves this.
Images and unreliable models. White product backgrounds break detection, so we find the real foreground with PIL.ImageChops.difference(). Cloud models can be unreliable, so we try gemini-2.0-flash, then gemini-2.5-flash, then gemini-1.5-flash, and finally fall back to local analysis that works offline.
Avoiding a toy "click to deliver" button. Delivery tracking uses courier-style waybills, a real carrier webhook endpoint (/api/v1/logistics/webhook), OTPs, and seal hashes.
PayPal Sandbox. When running headless, the sandbox won't let you capture an order unless it's approved in a browser. We create real sandbox orders through the REST API and mark them CAPTURED_SIMULATED, and we're upfront about that.
Accomplishments that we're proud of
- Blocked all 20 of 20 attack types in our benchmark and lost nothing, while the naive agent lost $10,699.01.
- Vault-only mode still lost nothing. With the Adversarial Sentry turned off, the token ceiling and merchant lock still held. The design doesn't depend on the filter being perfect.
- The swarm can recover from fraud by failing over to a safe store.
- A tamper-evident audit log that anyone can verify.
- A STRIDE threat model that is honest about our limitations, mapped to the AP2 and ACP agentic commerce protocols.
- 7 sponsor integrations: PayPal, AG Grid, Render, Postman, Zapier, Channel3, and APIMatic.
What we learned
- A prompt is not a security boundary. The prompt "Don't spend more than $250" blocked only 3 of 20 attacks. Real security came from code and cryptography.
- Isolating the browsing agent from the payment agent eliminates an entire class of attacks.
- Always keep a deterministic fallback, such as heuristic filters.
- Be honest. Our vault is a logical-isolation Python enclave with no hardware backing, and sandbox captures are simulated. Admitting that makes everything else more believable.
- Small purchases make no economic sense without batching.
What's next for PayGuard Swarm
- Open-source SDK in Python and TypeScript, compatible with LangChain, CrewAI, AutoGen, and OpenAI Swarm, so any shopping agent can be wrapped in PayGuard.
- Multi-currency escrow (INR, USD, EUR, GBP) with milestone-based release, for example after customs clearance.
- Merchant reputation graph: when one agent finds a bad store, the others learn of it.
- Physical verification with smart lockers, NFC seals, and driver scanners, paying only after the package seal is verified.
- Zero-knowledge proofs (ZK-STARKs) to prove sufficient funds without revealing a balance or card details.
- Company controls: department budgets, approval gates, and signed compliance reports (SOC 2, ISO 27001, RBI guidelines, EU AI Act Article 14).
- Hardware enclaves such as AWS Nitro Enclaves and GCP Confidential Space.