Inspiration

After Nepal's 2015 earthquake, UNICEF's emergency cash top-ups through the social-assistance system began paying in July, more than two months after the 25 April quake, and reached people already on those lists. Anticipatory programmes pay before the disaster instead: households are enrolled in advance and paid when a pre-agreed trigger fires. When WFP sent cash to Bangladeshi households days before the 2020 flood peak, about 100 days earlier than its 2019 response, they were 36% less likely to go a day without eating (WFP / Centre for Disaster Protection review).

Earthquakes can't be forecast, so the fastest honest version is to pay households enrolled before the quake, within minutes of it being confirmed: a first, pre-agreed transfer while the full assessment happens. An AI agent could make that call in minutes, but nobody should hand a language model a payout button: one poisoned news item could redirect the money. We built the version a cash-programme lead at a Red Cross national society or a cash NGO could trust, where the safety comes from the architecture, not from hoping the model behaves.

What it does

  1. Enrol before the quake. Field partners enrol households in advance. Nobody applies, so there is no form for fraud or injection to get in through.
  2. Trigger on real data. USGS, cross-checked against a second agency (EMSC). The hosted demo replays the real M7.7 Panama earthquake of 9 October 2026, so every run is reproducible.
  3. An AI agent proposes. Tiers come from rules agreed before the quake (distance bands scaled by magnitude, one tier up for vulnerability). The agent reads the agencies' impact reports and flags where those rules may under-serve people: in the Panama run it asked a person to check Macaracas and Santiago, where USGS reported deaths. Its output has no field for a payee, an amount or an account.
  4. A deterministic firewall decides. It recomputes every amount, enforces caps and blocks duplicates. It also enforces a floor: if a plan leaves out or underpays an eligible household, the reviewer sees who and how many dollars, and one click drafts the plan of everyone owed.
  5. A person approves; PayPal pays. Approved plans go out as one PayPal Payouts batch. In our sandbox run all seven payouts ($680) showed SUCCESS about 25 seconds after sending (our audit log); PayPal's own record has batch 9GE626X9SA3NE complete 34 seconds after creation.

Built for the cash-programme lead who signs off on every dollar: the firewall's settings are the programme's pre-agreed trigger and payment rules.

Also:

  • Traceable. Each batch links to a hash-chained audit log; "Tamper with a copy" shows the chain breaking, and /payouts reads batches back from PayPal to show they match, fees included.
  • No phishing. Recipients get a fixed note in their language naming the partner who enrolled them and its help line. The agent can't write to them.
  • Donations come from people and other AI agents through PayPal Orders v2. An agent can ask, but only a person can pay, up to an allowance that person set. Receipts are confirmed with PayPal's hosted MCP server (read-only get_order).
  • The firewall is an MCP tool. check_payout_plan lets any tool that drafts payouts dry-run its plan first: a plan that slips in an attacker's address comes back with the attacker blocked and six households worth $560 flagged as left out. No money moves.
  • A Red Team page anyone can run: 27 injection attacks against an agent we scripted to obey every one. 26 are held for a person and 1 is blocked outright, each by a rule other than the $300 limit. Six quieter attacks show their real outcome, including the one we don't stop.

How we built it

  • Capability restriction instead of detection. The agent can only name registry ids and tiers, and its notes are never sent, so an injection has nowhere to put an attacker. An advisory sentinel (patterns plus a small classifier) adds a second layer, but the guarantee doesn't depend on it. Only the PayPal module holds credentials, and it acts only on verdicts in the audit log, after re-running the firewall against the ledger as it is at that moment.
  • PayPal Payouts: one batch per approved plan, with two layers of idempotency (a request id hashed from the firewall verdict, and one payout per event and household in the database), so neither a retry nor a second plan version can pay anyone twice. Item statuses are reconciled with a GET on every signature-verified webhook, with polling as a fallback.
  • PayPal Orders v2 through the Server SDK. Pending or denied captures never credit the pool; refunds and reversals debit it. An integer-cents SQLite ledger reserves and debits a batch in one transaction before PayPal is called.
  • APIMatic Context Plugin: used before writing any PayPal code. It caught that payer.payer_id is deprecated, that the approval link is rel: payer-action, that the SDK's request log includes the token, and that the SDK has no Payouts or webhook verification (so those use REST).
  • Stack and design: Next.js and TypeScript, SQLite, AG Grid, Leaflet, hosted on Render. The firewall is pure (no I/O, no clock, no LLM), enforced by tests that scan its source and imports. The console uses the language of road signs, so status reads by shape as well as colour, and every hold says why a person must decide, in dollars and town names.
  • Replay mode and limits: the hosted demo replays a recorded agent run, including real sandbox payouts, so you can try the whole flow without keys. In the demo anyone can approve, pay or refund; a real deployment needs staff sign-in and two approvers above a threshold.

Challenges we ran into

  • Designing for a compromised agent, not a well-behaved one: the test harness swaps in a script that obeys every injected instruction, and a reviewer who approves everything.
  • Our own review found that capping what the agent can pay isn't enough: a hijacked agent could still quietly pay people less, leave them out, or phish them through the payout note. We added the floor rule and fixed notes.
  • PayPal batch webhooks carry no item detail, so we reconcile by fetching the batch; a failed webhook is processed on PayPal's retry instead of being dropped as a duplicate.

Accomplishments that we're proud of

  • $0 to anyone not owed in 27 of 27 attacks, judged against a hand-written table of what each household is owed. Agent-written text reached PayPal in none.
  • A poisoned feed can't quietly withhold aid: if the agent holds, forges an event id or leaves people out, deterministic code drafts the full owed plan for a person to approve.
  • Honest about what remains: a reviewer who approves without reading would still let under-payment through, and an insider swapping a payee address is not stopped. The page says so.
  • 868 tests in 38 files, green in CI with typecheck, zero-warning lint and the red-team suite, including a property test over 3,000 compromised-agent plans and a model-based ledger test.

What we learned

For AI agents that move money, "make the model safer" is the wrong place to put the guarantee. The model should propose; deterministic code should dispose. Limiting what the agent can express does more than trying to detect what it was told, and a floor matters as much as a ceiling.

On PayPal: the Server SDK has no Payouts or webhook verification, so those go to REST; verify webhooks on the raw bytes; batch webhooks carry no item detail, so GET the batch; book batch_header.fees or your ledger drifts from PayPal's.

What's next for Firstlight

  • Sign in with PayPal when creating an allowance, so the cap is bound to a verified customer up front.
  • Bands from USGS ShakeMap intensity at each home instead of distance, and enrolment on top of an existing government social registry.
  • A pilot with a cash-programme partner in Central America, with transfer values from the local minimum expenditure basket. A real deployment also needs identity verification and sanctions screening, which a sandbox can't demonstrate.

Built With

Share this project:

Updates

Submission history