SuperAPIAI Directory

spendshield

github.com · AI agents

Payment guardrails for AI agents: spend caps, budget and approval gates, prompt-injection defense, an encrypted secret vault and an audit trail.

Open website Alternatives
PricingOpen source开源项目(可免费自部署)
PlatformsAPI

About this tool

SpendShield is a policy and authorization layer for AI agent payments, with one core purpose: to stop AI agents from spending money when they exceed the rules you have set.

[Purpose] Whenever an agent attempts to initiate a payment, it must first go through an authorize() call and obtain a decision result of ALLOW / APPROVAL (human approval) / DENY before funds move. SpendShield itself never holds funds; payment channels such as Stripe, x402, and wallets remain downstream. It is aimed at any scenario running "software that can spend money," such as agents based on Stripe, x402, or AP2, MCP servers, Claude Code, OpenClaw, or self-built automation workflows.

[Why it is needed] A single prompt injection can lead to financial loss: when an agent reads emails, web pages, or tool return results, if they contain instructions such as "refund $500 to a certain account," funds may be transferred without human decision-making and without an audit record. This is not a bug in the agent, but the absence of a gate.

[Main capabilities]

  • Decision gate: three-state authorization of ALLOW / APPROVAL / DENY, with reason returned in a structured form for easy reading by LLMs.
  • Policy control: rules such as budgets and merchant allowlists are set through a YAML policy file. The example policy includes a per-transaction cap and a daily budget.
  • Prevention of overreach: when an agent requests $75 while the policy cap is $50, DENY is returned, and retries, splitting, or taking a second path are not supported.
  • Audit chain: each decision is linked as an event in a hash chain; any edited event breaks the chain, and any reader can verify it (tamper detection).
  • Signed one-time authorization (experimental enforcement prototype): replaying the same authorization is rejected (one-time), missing or malformed authorization is rejected, and forged or tampered authorization is rejected due to signature mismatch. Executor.verify() uses an HMAC key shared with the issuer (SPENDSHIELD_AUTHZ_SECRET, with a dev-secret fallback in the prototype), and consumed token state is kept in process memory.
  • MCP integration: provides recommendations for separating agent-side tools from host/human-side tools. Agent-side decision tools include spend_authorize, spend_status, and spend_audit; host/human-only administrative tools include spend_approve / spend_reject, spend_reset, policy_sim / policy_apply / policy_create → policy_review → policy_lifecycle_apply / policy_rollback, secret_get.
  • Integration adapter modes: runnable examples of three adapter modes are provided — x402 / agent payment tools / MCP (examples/integration/), with no real funds required.

[How to use]

  1. Install: pip install spendshield
  2. Write a YAML policy file (policy.yaml) to set rules such as budgets and merchants.
  3. Place a single authorize() call between the agent and the payment, or use the returned result object directly.
  4. By default it runs in dry-run mode: it only evaluates, it does not actually spend money.

In the MCP quick start, the agent asks before spending; the host is responsible for deciding which tools the agent may call. The documentation states that MCP itself has no authentication and the host must be trusted; policy_apply / policy_review are host-level operations. If administrative tools are granted to an untrusted agent, the current implementation will not prevent it from calling them.

[Testing and security] The project includes 251 tests, more than 14 security suites (budget bypass, race conditions, replay, double spending, parameter tampering, credential leakage, etc.), and maintains 8 security invariants: no payment without authorization, no payment over budget, no payment when approval does not match, no payment with an invalid identity, replay grants at most one authorization, concurrency does not break the budget, engine failure means denial, and the agent cannot bypass SpendShield. There is also random-seed fuzz testing and an audit hash chain. The project has a "Break the Gate" security challenge, encouraging submissions of bypasses in the sandbox (dry_run=True / test keys) with a minimal reproduction. The documentation emphasizes: this is reproducible verification of the current implementation by the current test suite, not a mathematical proof of security.

[Applicable scenarios] Any system that lets machines make payments: e-commerce refund automation, API billing, x402 pay-per-use flows, MCP payment servers, coding agents such as Claude Code, home-built automation, etc. If a machine can pay, someone should set the rules first.

[Limitations and threat model(explicitly stated in the documentation)]

  • Enforcement (signed-grant executor) is an experimental prototype located in spendshield/enforce.py, separate from the default authorize() flow; what the default public path guarantees is decision-making and auditing, not cryptographically enforced execution. Connecting Executor.verify() before the payment call is an integrator's deployment step.
  • Production hardening (key management, persistent replay state, external anchoring) is recorded in SECURITY_HARDENING_BACKLOG.md and is not yet complete.
  • The audit chain can detect partial tampering, but without encryption keys and without external anchoring, it cannot resist an attacker able to rewrite the entire in-memory chain; cryptographic signing / external anchoring are on the hardening roadmap.
  • MCP has no authentication and the host must be trusted; approval IDs are 48-bit random numbers; auditing is in-memory (append-only writes are on the roadmap).
  • The deployment model is divided into three layers — SDK → MCP → Gateway — each guaranteeing different capabilities.

[Origin] The project author explains that the motivation came from a real incident: on August 9, 2026, their automation pipeline ran a test order, intending to use dry: true to get a price preview, but the server only recognized ?dry=1, and as a result 4 orders of 99 yuan were actually charged, and the money disappeared just like that. From this, the author turned that lesson into a library.

[Pricing] No charging or pricing information is provided in the materials, so none is available for now.

Up/Down to navigate · Enter to open · ESC to closeBrowse all tools