One spend budget per wallet for AI agents: counted across every process, replica, key, permission and payment rail.
pip install walletcap==0.2.1 Copy PIP instructions
Your agent's spending limit forgets. This one doesn't. By ShadowPath.
Agent payment kits count "spent so far" per process, per key, per permission or per period. So a restart, a second replica, one more key, or the next period hands the agent a fresh budget. walletcap counts per wallet: one budget that every process, replica, key, permission and payment rail spends from.
The owner creates the budget once. Opening it never creates one; pass create: true only for a demo or first-run setup:
Most agent spend controls keep "spent so far" next to something temporary or repeatable: a process, a browser window, an API key, a delegate, one permission, or a fixed calendar period. The money, though, sits in one wallet. When the count and the wallet don't match, ordinary events (a restart, a second replica, another key or permission, the next period) can hand the agent a fresh budget against the same money.
ShadowPath measures spend controls against that pattern, on owned test chains with the vendors' own code. Findings go to the vendors first; this package is the fix, not the findings.
The count lives in a SQLite file that every process on the machine shares, and each payment is reserved inside one write transaction, so replicas racing for the last dollar can't both win. JavaScript and Python read and write the same file.
pay() reserves the amount, runs your payment, and records it as settled.
import { notSent } from 'walletcap'; throw notSent(error); // inside the payment function In Python, raise NotSent("card declined") inside the with block. Set payment.tx in the block to keep the transaction hash in the history, and use async with in async code.
budget.check('$5') answers { ok, reason, remaining } without spending. budget.reserve() gives you a reservation to commit() or release() yourself.
guard() puts the budget in front of any x402 v2 client from @x402/core, so it works under @x402/fetch. Use it as the one counter when the client has no CDP spend store.
budget.cdpStore() is walletcap's SQLite ledger behind CDP's SpendStore interface — not CDP's in-memory default. Replacing that default is the fix, not a second control.
Do not call both on one client: the CDP store and the guard each record the payment, so the budget would count it twice. budget.guard() refuses a client that already has CDP controls, and a client guarded first refuses CDP controls before signing.
To use the store, swap CDP's in-memory store for walletcap's, set maxCumulativeSpend (CDP only records through its store when a cumulative cap is set), and set allowedAssets: CDP never consults its store for a token outside the cap.
applySpendControls(client, { maxAmountPerPayment: { atomic: 50_000_000n, asset: USDC }, maxCumulativeSpend: { atomic: 150_000_000n, asset: USDC }, maxCumulativeSpendWindow: '24h', allowedAssets: [USDC], store: budget.cdpStore({ asset: USDC }), }); guard() is the other choice, and the one that prices every token: it refuses a USD stablecoin it cannot value instead of letting CDP count only the asset named in the cap.
walletcap's store re-checks the budget when CDP records a payment, so it holds across replicas on its own. When CDP removes a payment from its store, the store can't tell why, so the payment stays counted as in-flight until you check the chain and run npx walletcap release . Use CDP 1.56.0 or later; the store is tested against the published 1.60.0.
Run the Agentic Wallet's CLI and MCP server through walletcap, and every payment counts in the wallet's budget, whichever process, session or machine makes it:
import { X402ActionProvider } from '@coinbase/agentkit'; class BudgetedX402ActionProvider extends X402ActionProvider { async createX402Client(walletProvider) { return budget.guard(await super.createX402Client(walletProvider)); } } // AgentKit.from({ walletProvider, actionProviders: [new BudgetedX402ActionProvider()] }) Coinbase Spend Permissions, on chain For a limit the agent's own code can't go around, solidity/src/AccountCapSpender.sol is the spender for Spend Permissions. Deploy it with the SpendPermissionManager, the agent's address, the cap, the window, the per-payment max and the payees allowed. Grant Spend Permissions to the contract instead of the agent; the agent calls pay(permission, amount, payee). Every permission the account grants it then shares one rolling cap.
$ npx walletcap status Budget file /home/you/.local/state/walletcap/budget.sqlite 0xd797…ca02: $0.15 spent of $0.15 per 24h, $0.00 left · at most $0.05 a payment $ npx walletcap set --per-day 0.20 # what was spent still counts $ npx walletcap freeze # every process, every rail, now $ npx walletcap unfreeze $ npx walletcap history $ npx walletcap release # an in-flight payment you know never left Python ships the same commands as walletcap. Amounts are dollars; leave out the $ sign, which your shell would expand. Add --wallet when the file holds more than one budget, and --json for scripts.
The default file is per user: ~/.local/state/walletcap/budget.sqlite on Linux, ~/Library/Application Support/walletcap/budget.sqlite on macOS, and %LOCALAPPDATA%\walletcap\budget.sqlite on Windows. Set WALLETCAP_PATH, or pass path, to put it elsewhere. Both languages compute the same default.
The budget is as durable as that file. In a container, put it on a volume that outlives the container, or a redeploy starts a new file. Opening a budget does not create one: a missing file refuses every payment. The owner creates it once with npx walletcap set; pass create: true only for a demo or a first-run setup.
$ cd js && npm install && node --test # 58 tests $ uv run --with pytest pytest -q # 54 tests, from the repository root $ cd solidity/evm && npm install && node check.mjs .. # the contract on an EVM, no Foundry needed $ cd solidity && forge test # the contract's canonical tests, if you have Foundry The JavaScript suite runs the x402 guard against x402's own client and fetch wrapper, and runs restarts and racing replicas as separate processes, and drives the Agentic Wallet wrapper and MCP proxy against stand-ins for Coinbase's wallet and MCP server. The Python suite covers the ledger, the API, the CLI and one budget shared between both languages. solidity/evm/check.mjs compiles the contract with solc-js and drives it on an in-process EVM, covering what the Foundry tests cover.
One test is not here: the integration test that drives Coinbase's CDP spend controls through the shared store. It runs against a vendored build of Coinbase's SDK and lives in ShadowPath's own repository. Porting it to the published @coinbase/cdp-sdk is open work.
This package closes the gaps ShadowPath measured. Whether your configuration is closed is a measurement: ShadowPath runs your agent with every control switched on and certifies, in dollars, what can still get past your budget, signed and re-checkable offline. Get a certificate for your deployment.
agent-payments ai-agents budget guardrails spend-limit stablecoin usdc x402
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
None of the files in this release were uploaded with provenance metadata.
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.




