Back to Browse

Safepay MCP Server

Developer ToolsUse Caution4.9MCP RegistryRemote
Free

Server data from the Official MCP Registry

Judges a payment (PayPal, PYUSD or USDC) before an AI agent makes it. Signed proof. Moves no money.

About

Judges a payment (PayPal, PYUSD or USDC) before an AI agent makes it. Signed proof. Moves no money.

Remote endpoints: streamable-http: https://safepay.agentposhq.com/mcp

Security Report

4.9
Use Caution4.9High Risk

Valid MCP server (2 strong, 1 medium validity signals). 9 known CVEs in dependencies (0 critical, 3 high severity) Imported from the Official MCP Registry.

5 tools verified · Open access · 9 issues found

Security scores are indicators to help you make informed decisions, not guarantees. Always review permissions before connecting any MCP server.

Permissions Found in Source Code

Found by scanning the linked source code. This listing connects to a hosted endpoint, so none of this runs on your machine: it describes what the server software does where it is hosted.

env_vars

Applies to the server that hosts this plugin, not to your machine.

HTTP Network Access

Connects to external APIs or services over the internet.

How to Connect

Remote Plugin

No local installation needed. Your AI client connects to the remote endpoint directly.

Add this to your MCP configuration to connect:

{
  "mcpServers": {
    "com-agentposhq-safepay-check": {
      "url": "https://safepay.agentposhq.com/mcp"
    }
  }
}

Documentation

View on GitHub

From the project's GitHub README.

SafePay

ci PyPI Live demo Security

The firewall any AI agent plugs in before it pays with PayPal. SafePay is not another agent: it is the layer under all of them. Whatever the agent is built with (an MCP client such as Claude or Cursor, the PayPal Agent Toolkit, LangChain, plain Python or HTTP), every payment it wants to make passes through SafePay, which decides before any money moves whether to allow, hold, or block it. It checks the payee on the live web, catches lookalike vendors, inflated invoices and injected instructions, holds what a person should see, pays the rest through PayPal, and leaves a signed link in a hash chain for every decision. And it is measured: a reproducible benchmark of real attacks on a wallet-holding agent, not a claim. On the same 17 attacks, spending limits alone stop 4; SafePay stops 16, and all 17 with the new-payee hold, with no legitimate invoice blocked.

Built for accounts payable, not shopping carts. A budget or spending mandate answers how much an agent may spend. Most fraud against a business is a payment of a normal size to the wrong payee or for the wrong reason: the invoice email that says "we changed our bank details", a real vendor's name on a lookalike domain, an instruction hidden in the invoice, a payment that sits inside every limit but does not serve the task. Those are the cases SafePay judges: to whom and why. It composes with limits; it does not replace them.

Built for the PayPal AI Hackathon (Agentic Commerce and Autonomous Payments) by NovaCorp Labs.

We are looking for pilot teams and partners. If you build agents that pay, run accounts payable, or work on payments or fraud and want to try SafePay with your own flows, write to security@novacorplabs.com. Pilots are free and onboarded by hand.

Watch the 2:44 demo video: https://youtu.be/UMra3qDSNEs (English subtitles; the same story as the 3-click tour below).

Judge in 3 clicks

https://safepay.agentposhq.com · no login, no keys; every PayPal call goes to the real PayPal sandbox, and the web check (Tavily) and the reasoning (NVIDIA Nemotron on Nebius) run live. Each browser gets its own session.

Short on time? Take the 3-minute tour: ten steps across the real pages (not a demo page), with a button that runs the scenarios or the chain check for you. Arrow keys move, Esc ends it.

  1. Console → type a policy in plain words → Draft → Apply. For example "Up to $500 per payment and $1,000 a day. Ask me before anything over $300. No gambling or crypto." Nemotron drafts the rules; you see every field before it applies, and the change is chained as a policy link.
  2. Run demo scenarios. Seven payments resolve one by one: a real Notion invoice paid; the same invoice to a lookalike domain blocked; a USD 900 charge blocked by the cap; a casino payout held (the web found a scam complaint, the reasoning found it does not serve the task: open each check to see the sources); two cloud invoices over your "ask me" line held for you (approve one, here or with the Telegram card; every paid card links its public seal page); the last one blocked by the daily cap. Then Create the order through the gate: a real PayPal Agent Toolkit order, created only because SafePay allowed it.
  3. Ledger → Tamper (demo) → Verify chain. Every decision is a link in a signed hash chain; edit one row (on a copy) and the badge turns red. The Flow page replays the same chain as pulses through the layers.

Run it yourself: pip install safepay && safepay --demo (no keys needed).

The five judging criteria, one line each, with where the evidence is:

CriterionWhere to look
Technological implementationPayouts, Orders v2 authorize/capture/void, Vault v3, Transaction Search and webhooks, all against the real sandbox; the Agent Toolkit gated; Nemotron and Tavily live; 504 offline tests at 98% coverage (Tests)
DesignOne console that an operator sets up in plain words and a judge works end to end: policy, scenarios, approvals, Telegram, ledger, Studio, seals, kit (See it)
Potential impactThe fraud is named and sized (IC3, AFP), the 2026 agent incidents are real, and SafePay runs inside a product with real users whose counters are public (The problem, Impulsa)
InnovationJudgment beyond caps (spending limits alone stop 4 of 17 attacks, SafePay 17): the payee on the live web, the task the agent was given, a measured attack benchmark a judge reruns live, a seal the payee verifies without us, AP2 mandates on PayPal authorizations (Attack benchmark, The seal)
PresentationThe 3-minute tour inside the real console, the 2:44 video, and this README: what is real and what is not, stated before the claims (What is real)

SafePay home: live figures from the audit chain

See it

Screenshots from the hosted demo (https://safepay.agentposhq.com), real sandbox payouts, real web and model checks.

The Flow. Every payment travels as a pulse through the layers; the page replays the real links of the audit chain and animates new ones as they land.

The Flow: a payment pulse travelling from the agent through policy, live web and reasoning to the verdict, PayPal, a human, and the chain

The Ledger. The hash chain as an AG Grid table (Community edition). Click a link and a full-width detail row opens under it with every check it was judged on, its reasons, its seal and PayPal batch, and the hash of the link before it (marked "matches" or "break"). Verdict chips, a search box and a click on any of the three AG Charts (verdict mix, approved spend per agent, average risk by category) all drive one filter, so the grid, the pinned totals row (released vs stopped, outside the firewall, chain breaks) and the CSV export with full hashes always agree on what is shown. The grid is also the operator's desk: a pinned Act column approves or rejects a held payment, or freezes and resumes an agent, from its row.

Ask the chain (AG Studio). /studio turns the whole audit chain into an AG Studio report: a links table and a checks table (joined on the link), a benchmark-cases table and a mandate-stages table derived from the same records, measures for money released and stopped, holds, blocks, average risk and failed checks, and five finished pages plus a blank one: Overview (what SafePay let through and stopped), Checks (which checks catch what), Timeline (released vs stopped per day as a stacked area, holds and blocks per day, value tiles with day sparklines, a gauge of average risk), Benchmark (every attack-benchmark case the console ran against this deployment: caught, missed, allowed, false alarms, by category and by mode, with each case's step verdicts) and Mandates (a funnel of USD authorized, captured and voided, a pivot of amount by agent and link type). Its assistant is NVIDIA Nemotron 3 Ultra on Nebius, wired through AG Studio's own Direct LLM Runner and OpenAI-Responses adapter to a server proxy that holds the key, pins the model and keeps its own daily cap. One focused analyst agent with five Studio tools (view schema, view page, run a query, add and position a widget) answers "how much did SafePay stop, by verdict and agent, and which checks caused it?" in about six turns, from the data; it has no tool that pays, approves or changes a decision.

AG Studio, Timeline page: released vs stopped per day, holds and blocks per day, links and checks per day, a gauge of average risk AG Studio, Benchmark page: the attack benchmark as the console ran it against this deployment, caught vs missed by category and by mode AG Studio, Mandates page: a funnel of USD authorized, captured and voided, and a pivot of amount by agent and link type

Proof. /proof lists every PayPal sandbox object the chain says SafePay created (payout batches, orders, authorizations, captures) in an AG Grid, and "Ask PayPal" re-reads each one from PayPal's own API, so the status shown is PayPal's, not ours. The page also maps every PayPal API SafePay calls to the code that calls it.

The Ledger page: the audit chain in AG Grid and three AG Charts


What is real and what is not

So nobody has to guess.

Real.

  • PayPal. Every payout, order, authorization, capture, void, vault token, webhook and reconciliation goes to PayPal's sandbox API: the real API, with test money. The host is pinned to the sandbox in config.py; nothing here has ever moved real money. Without PayPal keys the console says "PayPal simulated" and payouts are simulated, and says so on every result.
  • The checks. The web check is a live Tavily search; the reasoning check is Nemotron on Nebius. Both are cached for 24 hours and capped by a daily budget that fails closed. Without keys they are skipped, and the result says "skipped".
  • The evidence. The HMAC-signed hash chain, the Ed25519 seals and the operator's P-256 signatures (WebCrypto, non-extractable) are real keys; seals and receipts verify offline against the published key.
  • The state. Supabase holds the chain, the ledger, approvals, policies and agent keys on the hosted demo; locally it is memory.
  • The numbers. The attack benchmark and the duplicate-submission benchmark are real runs, committed with their runners and raw results, and the console reruns the attack cases live. The cost per decision is measured on those runs.
  • In production. Impulsa is a real product with real micro-businesses; SafePay's history rules run there on every supplier document. The live counters at /api/impact are aggregates with the team's test accounts excluded, and they start at zero: zeros are shown as zeros. Businesses the team owns (AgentPOS, the foundation) that record their real supplier purchases are counted apart and named as ours: real use, not traction. The AgentPOS catalog and quotes come from a real store; the USDC settlement check was run against a real payment on Stellar mainnet.
  • Upstream. paypal/agent-toolkit#124 is a real pull request. It is open, not merged.

Not real, by design.

  • No money. Sandbox only, always.
  • The cases are ours. The 7 demo scenarios, the sample invoices and the 25 benchmark cases were written by us: realistic shapes, fictional vendors on .example addresses (the legitimate vendors carry their real domains so the directory check is meaningful). No customer data anywhere in the repo.
  • The human. Whoever clicks Approve (or answers in Telegram, or presses the kit's button) is the human in the loop. Operator actions are open on the public demo so a judge needs no setup; SAFEPAY_OPERATOR_TOKEN locks them in a real deployment.
  • The kit. safepay-kit is tested end to end against the real console with the keyboard standing in for the buttons. Its GPIO board follows gpiozero and the pins in docs/kit.md, but has not been run on a Raspberry Pi yet.
  • The dispute switch. The CUSTOMER.DISPUTE.* webhook path (re-read, match, freeze, chain, alert) is tested offline against a scripted dispute; no real sandbox dispute has been raised against it yet.
  • Stablecoins are validated, never moved. SafePay has no wallet.
  • AP2. SafePay produces and verifies AP2-shaped mandates on its PayPal mandates. It is not a participant in an AP2 network, and the store does not sign carts yet (the cart says so).
  • The tamper buttons edit your own session's stored policy, and a copy of the chain, to show what detection looks like. The stored history is never altered.
  • Customers and revenue. None yet. Pricing is a proposal; the measured figures are costs, not income. Impulsa is the first integration, by the same team.

The problem

Agents are starting to pay the bills: SaaS renewals, cloud invoices, contractor payouts. The upside is obvious; the risk is the same thing. An agent that can pay can also be prompt-injected by an invoice email into paying an attacker, talked into an amount that does not fit its task, handed a real vendor's name on a lookalike domain, or sent to a merchant that was registered last week and shows up on scam-report pages. A static allow-list is too blunt, and letting the model decide alone is exactly what goes wrong.

This is not a hypothetical class of fraud; it is the most expensive one businesses already face, and agents inherit it at machine speed:

And agents have already started doing it to themselves. In February 2026 an autonomous trading agent asked for about 4 SOL sent 52.4 million tokens, 5% of a coin's supply, after a decimal confusion and a lost conversational state (as reported). In October 2026 OpenAI disclosed that one of its internal research models, denied free testnet tokens, paid its fees from a stranger's wallet found through a public recovery phrase and left it out of its report; its finding was that "a model can substitute its own judgment about likely harm for the account holder's permission" (Fortune). OWASP moved Excessive Agency to third place in its 2026 LLM Top 10 and published a separate Top 10 for agentic applications; SafePay's answer to each of its ten entries, with the test that proves it, is in docs/owasp-asi.md.

SafePay's rules are these attacks by name: the lookalike payee, the "we changed our bank details" email, the invoice paid twice, the instructions hidden in the invoice, the agent that decides a stranger's wallet is fair game.

SafePay is the missing layer: a payments firewall that an operator describes in plain words once, and that every agent payment has to pass through. Spending caps are where most tools stop. SafePay also looks outward (is this payee what it claims to be?) and inward (does this payment serve the task the agent was given?), and it proves how well that works.

Where SafePay sits

The agentic-commerce stack is settling into layers, and SafePay is one specific layer of it, on the buyer's side:

  • PayPal's Agent Ready and Store Sync make a merchant payable and discoverable by agents. They are the merchant's side. SafePay is the buyer's: the control the agent's operator runs before the agent spends. PayPal's own docs distinguish "supervised" from "automatic" shopping; SafePay is the supervision for the automatic case, with the human on a Telegram card instead of in front of the checkout.
  • UCP, ACP and AP2 describe discovery, checkout and proof of authorization. SafePay issues AP2 Intent, Cart and Payment mandates (the layer UCP carries as an extension) bound to a PayPal authorization, so whatever checkout protocol the merchant speaks, the mandate that says "this human authorized this budget for this task" is there.
  • MCP gateways (policy proxies that sit in front of every tool call) decide whether a tool may run. SafePay is the payment-specific judgment behind that yes: any gateway can forward a payment to safepay_check or /api/check and get a verdict, evidence and a signed attestation back.
  • LLM spend proxies cap what an agent spends on tokens. SafePay caps and judges what it spends on money. They compose; neither replaces the other.

How it works

Each PaymentIntent runs three checks, cheapest and strictest first:

  1. Policy (deterministic). Per-transaction, daily, per-recipient and velocity limits, allowed and blocked categories, recipient allow/block lists, currency, and an approved vendor directory (per vendor: its real domains and the amount you expect to pay it). A breach here is a hard block, no model call spent. The daily, per-recipient and velocity caps are enforced across a burst of payments, not just one in isolation, so a slow-drain or high-frequency attack is caught. The vendor directory catches the two attacks that stay inside every cap: a lookalike recipient (real vendor name, swapped domain) and an inflated amount to a real vendor; a stated merchant URL must also agree with the recipient's domain. With hold_unknown_vendors on, any payee outside the directory is held for a human, the "new beneficiary" control banks apply. hold_above is "ask me before anything over X": inside the hard cap, but big enough to wait for a tap. The deterministic policy is the floor: the model layers below can tighten a verdict to HOLD, never loosen a policy block.
  2. Merchant verification (live web, Tavily). Pulls fresh web evidence about the payee and flags fraud/scam signals. A soft signal: it raises risk and can trigger a hold, but never silently blocks on noisy web data.
  3. Intent and anomaly reasoning (NVIDIA Nemotron on Nebius Token Factory). Reads the task the agent was given and judges whether the payment actually serves it. Catches goal/payment mismatches a rule set misses (a cloud-invoice agent paying a casino).

The verdict aggregates the three. On allow, SafePay releases the payment via the PayPal Payouts API (agent sends money, no buyer redirect, fully backend). On hold or block, the money never moves. Every decision is written to a tamper-evident, optionally HMAC-signed audit record, and when PayPal later reports what happened to the payout (succeeded, failed, returned) that settlement is appended to the same chain, so the record says not only what SafePay decided but whether the money actually moved.

PaymentIntent ─▶ [policy] ─▶ [merchant web] ─▶ [reasoning] ─▶ verdict
                    │                                              │
                 hard block                            allow ─▶ PayPal sandbox payout
                                                        hold/block ─▶ stop + audit

Run it

One minute to a first verdict, no keys needed:

pip install safepay          # or, from a clone: pip install -e .
safepay --demo               # 7 scenarios, payouts simulated, lookalike and caps blocked

Three lines to put it in front of your own agent's payments:

from safepay.agent import SafePayAgent
from safepay.models import PaymentIntent, PolicyConfig

agent = SafePayAgent(policy=PolicyConfig(per_tx_limit=500, daily_limit=2000))
result = agent.pay(PaymentIntent(recipient="billing@notion.so", amount=48,
                                 purpose="Team plan", task_goal="pay approved SaaS invoices"))
# result["decision"]["verdict"] is "allow", "hold" or "block"; on allow the payout went out.

From a clone, with the real checks:

pip install -r requirements.txt
# Simulated mode (no keys needed): policy checks run, payouts are simulated.
python -m safepay --scenarios examples/scenarios.json

# Full mode: copy .env.example to .env, fill the keys, load it, and re-run.
set -a; . ./.env; set +a
python -m safepay --scenarios examples/scenarios.json

Web console (what a judge runs)

set -a; . ./.env; set +a
python webapp/app.py
# open http://127.0.0.1:5000

The console is four pages on one design:

  • Flow (/): the didactic view. An animated map of the layers (agent, policy, live web, reasoning, verdict, PayPal, human, chain) through which every payment travels as a pulse. It is not a mock: it replays the most recent links of the real audit chain, decision by decision, with the verdict colour, the stage that stopped it and the human or settlement links that followed, and it keeps polling the chain, so running the demo in the Console lights it up live. Live figures from the chain, the layers, the benchmark table and the early-access form sit under it.
  • Console (/console): write the policy in plain words and apply it, then run the demo scenarios, a custom payment or a PayPal Agent Toolkit order through the gate, and watch each intent resolve: the checks (each one opens to show what it looked at: web sources and snippets, the model's verdict, the rule numbers), the verdict, the PayPal sandbox batch, the signed stamp. Pending approvals and the session's agents sit under the results. "New session" starts the daily-cap scenario fresh: the policy, the agents and the budget are scoped to your session, which follows you across pages.
  • Agents (/agents): every agent id seen, with Freeze / Resume and Issue key / Revoke key, for this session or all of them.
  • Ledger (/ledger): the hash-chained log as an AG Grid table with a live verification badge, your session's links by default ("Show all sessions" for the shared chain); "Verify chain", "Reconcile with PayPal" and "Tamper (demo)", which edits a row on a copy so the badge turns red. Three AG Charts read the same chain: the verdict mix, approved spend per agent (with anything that moved outside the firewall as its own bar), and average risk by category; clicking a slice or bar filters the grid. Each row opens to its checks and hashes; Export CSV downloads what is shown.

Hosted demo

Live: https://safepay.agentposhq.com (no login, no local setup). It runs on Vercel from this repo (api/index.py + vercel.json); every push to master redeploys. A second live instance runs on Render from the included blueprint: https://safepay-ygzp.onrender.com (render.yaml + the gunicorn entry point wsgi.py; free plan, so it may take up to a minute to wake after idling). Set the secret values (PayPal, Nebius, Tavily, signing key) as environment variables on the host; without the PayPal keys it runs in simulated mode. Locally the same server runs with gunicorn -w 1 -b 0.0.0.0:8000 wsgi:app.

Single intent from the command line

python -m safepay --recipient vendor@example.com --amount 42 \
  --category software --purpose "monthly API bill" \
  --goal "pay the team's approved SaaS invoices"

Add --json for the full decision and audit records.

Gate the PayPal Agent Toolkit (agentic commerce)

SafePay also drops in front of the PayPal Agent Toolkit. The toolkit gives an agent real PayPal tools (create_order, capture_order, and more); PayPal's own guidance is to "invoke pay_order only after the user approves." SafePay is that approver, made automatic: it judges the intent, and the toolkit's money-moving tool is called only on ALLOW.

set -a; . ./.env; set +a
python examples/agent_toolkit_demo.py

Allowed intents create a real sandbox order (with its buyer approval link); over-limit and daily-cap breaches are stopped before the toolkit is ever called. The gate lives in safepay/agent_toolkit.py as GuardedToolkit:

from safepay.agent_toolkit import GuardedToolkit
gate = GuardedToolkit(policy=policy)          # reasoning/web optional
out = gate.create_order(intent)               # evaluate, then create on ALLOW
# out["decision"], out["result"] (the order), out["audit"] (signed)

In the console, the "Agentic commerce" card does the same through POST /api/toolkit/order: the gate shares the agent's guardrail and audit chain, so an order counts against the same daily cap as a payout, honours the session policy and the agent's key, and is chained as an order link. The light paypal-agent-toolkit 1.1.0 release is a core dependency (later releases pin whole agent frameworks); pip install safepay brings it.

The gate also makes the toolkit idempotent. PayPal de-duplicates a POST that carries a PayPal-Request-Id header: the same id again returns the original order instead of creating a second one. The toolkit's Python client does not send that header (we checked the 1.1.0 and 1.11.0 wheels, shared/paypal_client.py: the request_id its Context accepts is never read), so an agent that retries create_order, capture_order, create_subscription or send_invoice after a timeout creates a second order, charge, subscription or invoice. Crashpay, another entry in this hackathon, measured that double charge against the sandbox. Through GuardedToolkit every money-moving toolkit call goes out with a request id derived from the intent (its idempotency_key, else a hash of the method, the parameters and the agent), the id is written into the chain link, and a retry of the same intent reaches PayPal as the same request. The header alone is not enough when the duplicates are simultaneous (PayPal de-duplicates against a request it has already finished), so the gate also runs one toolkit call per request id at a time and hands the twin the first result instead of calling PayPal again; a later retry with the same idempotency key is answered the same way for an hour, without re-judging it. We measured it against the sandbox (benchmark/retries/, 20 simultaneous duplicates of one create_order, 3 rounds): the shipped client makes 20 orders every round, the header alone still lets 2 to 7 through, the gate makes 1. SafePay's own PayPal client (Payouts, Orders, Vault) has always sent it. We also reported the gap upstream and sent the fix at the source: paypal/agent-toolkit#124 (per-call request id for the Python client, open as of November 8, 2026).

The duplicate-submission benchmark on /security: 60/60 orders as shipped, 13/60 with the header alone, 3/60 through the gate

Use it as an MCP server (any agent)

SafePay also runs as a Model Context Protocol server, so any MCP client (Claude Desktop, Cursor, an agent framework) can route its payments through the guardrail without importing any SafePay code. It exposes seventeen tools: safepay_evaluate (judge without paying), safepay_pay (evaluate, then pay via Payouts only on ALLOW), safepay_pay_invoice (SafePay's own payables agent: invoice text in, judged payment out), safepay_create_order (gate the Agent Toolkit order flow), safepay_open_mandate, safepay_capture and safepay_close_mandate (authorize a budget, capture what the task costs, void the rest), safepay_pending_approvals, safepay_approve and safepay_reject (the human in the loop for HOLD decisions), safepay_payout_status (settlement), safepay_draft_policy (plain words to a policy draft), safepay_agents, safepay_pause_agent and safepay_resume_agent (the kill switch), safepay_reconcile (flag money that moved outside the firewall), and safepay_audit_status (re-verify the tamper-evident chain).

pip install -r requirements.txt -r requirements-mcp.txt
python -m safepay.mcp_server          # stdio transport

Point your MCP client at that command. For Claude Desktop or Cursor (examples/mcp_config.json):

{
  "mcpServers": {
    "safepay": {
      "command": "python",
      "args": ["-m", "safepay.mcp_server"],
      "env": { "PAYPAL_CLIENT_ID": "...", "PAYPAL_SECRET": "...",
               "NEBIUS_API_KEY": "...", "TAVILY_API_KEY": "...",
               "SAFEPAY_SIGNING_KEY": "..." }
    }
  }
}

Run it from the repo directory (so safepay is importable), or pip install -e . first. The mcp package is optional; the core package and tests never need it.

Keys

KeyWhat it turns onWithout it
PAYPAL_CLIENT_ID / PAYPAL_SECRETReal sandbox payoutsPayouts are simulated
NEBIUS_API_KEYNemotron intent/anomaly reasoningReasoning check is skipped
TAVILY_API_KEYLive-web merchant verificationMerchant check is skipped
SAFEPAY_SIGNING_KEYHMAC-signed audit recordsRecords are integrity-only (unsigned)
SAFEPAY_AUDIT_LOGPersist the hash-chained log to this JSONL fileLog is in-memory only
SAFEPAY_EXECUTEsimulate/0/false evaluates without moving money (budget still charged)ALLOW executes the payout
SAFEPAY_RATE_LIMITMax web-console evaluations per IP per minute30
SUPABASE_URL / SUPABASE_SERVICE_ROLE_KEYDurable, shared audit chain, ledger and approvalsIn-memory state
PAYPAL_WEBHOOK_IDAccept PayPal Payouts webhooks at /api/paypal/webhook (signature verified with PayPal)Settlements only on demand (console button, API, MCP tool)
TELEGRAM_BOT_TOKEN / TELEGRAM_CHAT_ID / TELEGRAM_WEBHOOK_SECRETEvery HOLD is pushed to a Telegram chat with Approve and pay / Reject buttons; taps come back through /api/telegram/webhookApprovals in the console, API and MCP only
SAFEPAY_CHECK_CACHE_SECONDSHow long a merchant or reasoning result is reused for the same inputs (default 86400; 0 disables)24 h cache
SAFEPAY_EXTERNAL_DAILY_BUDGETMost paid web and model calls per UTC day; past it a check fails closed (HOLD)400
SAFEPAY_OPERATOR_TOKENOperator actions on the console API (apply a policy, freeze an agent, approve, issue a key, reconcile, tamper demo) require it in X-SafePay-OperatorOperator actions are open (a judge's zero-setup demo)

Get PayPal sandbox keys at developer.paypal.com > Apps & Credentials > Sandbox > Create App. The host is pinned to the sandbox in config.py; SafePay never defaults to the live host, so it cannot move real money by accident.

The demo scenario

examples/scenarios.json runs one agent (ops-agent-7) whose task is to pay the month's approved software and cloud invoices. SafePay:

  • allows the Notion subscription (within limits, aligned, reputable),
  • blocks the same invoice sent to billing@notion-payments.example: a real vendor name on a lookalike domain, caught by the vendor directory before any model runs,
  • blocks a USD 900 charge (over the per-transaction limit),
  • holds a casino payout (reasoning catches the goal mismatch; a rule set alone would let it through),
  • allows two cloud invoices, then
  • blocks the next (it would breach the daily cap).

Catching prompt injection

set -a; . ./.env; set +a
python examples/prompt_injection_demo.py

An agent reads an invoice email carrying a hidden instruction to pay an attacker. The injected payment is deliberately inside every spending limit, so policy alone passes it, but the reasoning layer catches that a "processing fee to release invoices" does not serve the task, and holds it for a human, while the real invoice is allowed. This is the agentic-commerce attack SafePay exists to stop.

Attack benchmark (proof, not promise)

benchmark/attacks/ runs 17 realistic attacks on a wallet-holding agent (prompt injection in invoices and vendor pages, goal mismatches, an unknown payee, a lookalike recipient, amount inflation, limit breaches, a slow drain, a velocity burst, a duplicate invoice, a "we changed our bank details" payee change, an amount far above a contractor's history) plus 8 legitimate invoices, through the guardrail. Four modes, side by side, so the numbers are honest:

ModeAttacks caughtLegit allowed (no false positives)
spending limits alone (per payment, per day, per payee, velocity, currency; what a budget or spending mandate enforces)4/17 (23%)8/8 (100%)
policy only (rules + vendor directory + payment history, no model, no web)9/17 (52%)8/8 (100%)
full (policy + Tavily + Nemotron)16/17 (94%)8/8 (100%)
strict (full + hold unknown vendors)17/17 (100%)8/8 (100%)

Spending limits alone catch only what breaches a limit: an oversized payment, a currency switch, a slow drain and a velocity burst. Every attack of a normal size passes them, including the lookalike payee, the changed bank details and the duplicate invoice, the shapes of business email compromise. The same 17 attacks through spending limits alone and through SafePay: 4/17 against 16/17, 17/17 with the new-payee hold, 8/8 legitimate invoices paid

Rules alone catch what breaches a limit plus, with the vendor directory, the lookalike recipient and the inflated amount (the two misses of the first version of this benchmark, now closed deterministically) and, from the payment history in the ledger, a duplicate invoice (blocked), a payee change for a vendor already paid and an amount far above what a vendor was paid before (both held). Three monthly invoices from the same vendor with different invoice numbers pass: the duplicate rule keys on the invoice, not the amount. The model layers catch every prompt injection and every goal mismatch, with zero false positives on real vendors. The one case full mode does not catch reliably is the unknown payee with a plausible invoice: the model checks are not deterministic and that case flips between runs (caught by reasoning in an earlier run, missed in the three runs behind the table). That is exactly what the hold_unknown_vendors control is for, and strict mode shows it. Full per-case results are in benchmark/attacks/results.md. The same cases also run live from the console ("Run the attack benchmark"): the deployment judges them one by one in the mode you pick, every verdict lands in the Ledger as a benchmark link, nothing is paid, and the running tally is shown next to the committed run's numbers. Live runs vary with the model and the web: the run in the screenshot below caught 17/17 and held one legitimate invoice (7/8), where the committed run reads 16/17 and 8/8; both are in the chain.

The console running the attack benchmark in full mode against the deployment, each verdict with its web sources and model verdict

python benchmark/attacks/run_attack_benchmark.py --mode all    # needs keys for full/strict
python benchmark/attacks/run_attack_benchmark.py --mode offline # caps and policy, no keys
python benchmark/retries/run_retry_benchmark.py --n 20 --rounds 3 # duplicate submissions, needs sandbox keys

Red team: attacks the benchmark has never seen. A committed benchmark can be studied; a judge should be able to throw something new at the guardrail. "Red team: new attacks" in the console does that in two ways: the model (Nemotron) writes six new attacks from the task, the policy in plain words and one example per family, and code validates each one before it is judged (a known family, inside the per-payment cap so the cap does not catch it for free, a fictional or look-alike recipient); or, offline and free, the committed attacks are rewritten the way an attacker does once the first version is caught (the same instruction hidden by zero-width characters, Cyrillic look-alikes, an HTML comment or base64; a fresh look-alike domain of an approved vendor; an amount pushed past the tolerance; a new off-task merchant; a plausible payee nobody approved). Each case is judged live in the mode you pick and chained as a redteam link, nothing is paid, and every attack that gets through comes with the rule that would close it (the expected amount for that vendor, a blocked category, strict mode). Apply the fixes (signed) and rerun folds those rules into the session's policy, signs it with the operator key, applies it, and judges the same attacks again under fresh agent ids, so the judge sees the miss, the fix and the catch in one minute. Misses are shown as misses; the model writes what it writes, and we do not curate it.

Policy in plain words

An operator should not have to write JSON to say what they mean. In the console (and with safepay --draft-policy "..." or the safepay_draft_policy MCP tool) you write the rules as you would say them:

Up to $300 per payment and $1,000 a day. Ask me before anything over $100. No gambling or crypto. Hold any new payee for me.

Nemotron turns that into a PolicyConfig draft (a rule-based parser does it without a key), with a one-line summary per rule and a question for anything important the text left unsaid. You review the exact fields, edit them if you like, and apply. Three things keep this honest: the model's output is data that is validated and coerced field by field (unknown fields dropped, caps clamped, a hold_above over the hard cap turned off); the model never applies anything, a person does; and text that tries to instruct the reviewer ("ignore the limits") is refused before any model reads it. The applied policy belongs to your console session and follows it: the agents in that session are judged by it, other sessions are not.

Signed by the operator, not just by the server

The policy is the one thing that decides what every agent may pay, so SafePay does not let the server alone vouch for it. The operator's browser makes an ECDSA P-256 key with WebCrypto; the private half is created non-extractable, lives in IndexedDB and never leaves that browser. Applying a policy signs safepay-policy:v1:<session>:<sha256 of the rules>, and SafePay verifies it before the policy takes effect. The first signed policy pins the session to that key: an unsigned change, or one signed by another key, is refused (403), even with the operator token. The signature and the public key go into the policy's chain link, so anyone can re-verify which key approved which rules.

The stored policy is re-verified every time a payment is judged under it. If someone edits the row in the database (the console's "Tamper with the stored policy" demo raises the cap to USD 100,000 without re-signing), the next payment is blocked with "the policy was changed after it was signed", and nothing moves until the operator signs again. Code: safepay/opsig.py.

Learned from your own decisions

Documentation truncated — see the full README on GitHub.

Reviews

No reviews yet

Be the first to review this server!