Skip to content
tsang326Public

About

Human-in-the-loop approval and policy layer for AI agents that move money through PayPal

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

45 Commits

Folders and files

Repository files navigation

Interlock

A human-in-the-loop approval and policy layer for AI agents that move money through PayPal.

An agent connected to PayPal's Agent Toolkit can issue refunds, cancel subscriptions, concede disputes and send invoices. Interlock sits between the agent and that power: the agent may only propose an action, and a policy engine decides whether it runs on its own, waits for a person, or is refused. The server alone talks to PayPal, and every decision is appended to a tamper-evident log.

Built for the PayPal AI Hackathon, against the PayPal sandbox.


Why this exists

The Model Context Protocol specification (2026-07-28, Security and Trust & Safety) says both of these things:

Hosts must obtain explicit user consent before invoking any tool.

While MCP itself cannot enforce these security principles at the protocol level, implementors SHOULD […] build robust consent and authorization flows into their applications.

The same section adds that "descriptions of tool behavior such as annotations should be considered untrusted".

Interlock is built in the gap between those two sentences. PayPal's Agent Toolkit exposes 47 tools, including create_refund, cancel_subscription and accept_dispute_claim. Its configuration can switch whole product areas on or off, but there is no per-action approval step for the merchant side. Meanwhile the PayPal Developer Agreement (Β§1.3, App ID and API Credentials) is explicit about where the consequences land:

You are liable for all activities performed with your App ID, API Credentials or other PayPal Account credentials.

A merchant who hands an agent those credentials has handed over the ability to move money, keeps the liability, and gets no human checkpoint anywhere in the stack.

This is the merchant's side of the problem. Buyer-side approval already exists β€” a payer approves a payment before it is captured. What is missing is the back office: refunds, disputes, invoices and subscriptions, where the money leaves the merchant's own account.


How it works

      agent token                                          reviewer token
   (propose + read)                                     (decide + set policy)
                    the agent never holds PayPal credentials
                                      β”‚
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   proposes   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   approved only   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚  Agent   β”‚ ───────────► β”‚    Interlock     β”‚ ────────────────► β”‚ PayPal  β”‚
   β”‚ (gpt-4.1)β”‚              β”‚  policy + review β”‚                   β”‚   API   β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜              β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ◄──────────────── β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚                             β”‚            what PayPal         β–²
        β”‚  reads freely          β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”       actually holds      β”‚
        └───────────────────────►│  holds  β”‚  auto-approve Β· human Β· refuse
         16 read-only calls      β”‚  the    β”‚
                                 β”‚  keys   │──────► append-only, hash-chained audit log
                                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Of the toolkit's 47 tools:

15 read-only tools the agent calls them through Interlock, and Interlock calls them itself to check a proposal against PayPal's own record
9 money-moving actions the agent can only propose; Interlock decides and executes
the remaining 23 never wired up, so they are not reachable at all

Plus one call the toolkit has no tool for β€” reading a capture β€” which Interlock makes against the REST API underneath. That is the sixteenth readable call.

The console says 14, not 16, and that is deliberate. All sixteen are allow-listed, but two of them cannot answer from a sandbox app: get_shipment_tracking needs a scope this app was never granted and PayPal returns a bare 403, and get_merchant_insights is refused by the toolkit itself before a request is made. Asking for either gets 501 unavailable_here naming the reason and listing what does work, and neither is offered to the agent or counted on screen. All sixteen were called against this app's own credentials on 2026-10-20 to establish which fourteen answer; on a live account with the scopes granted, the count is 16.

That last row matters: Interlock is default-deny. pay_order, for example, exists in the toolkit and is simply not connected. The claim is not "we gate every dangerous tool" β€” it is "no money-moving call reaches PayPal except through executeApproved, and it runs only for a proposal that has already been decided". Reads reach PayPal by their own path, which moves nothing, and the demo seed is the one explicit exception: server/src/seed.ts calls executeApproved directly to create the invoices the queue is about, because there has to be something real to decide on before anyone has decided anything.

The rule the whole design rests on

Policy runs on facts read out of the request, never on the agent's account of itself.

When an agent files a proposal it may also state what the action is worth. That statement is displayed to the reviewer and recorded, and it is never used to decide anything. Interlock derives the amount and the target from params β€” the object that will actually reach PayPal β€” and policy sees only those.

This is not theoretical. Two ways an agent gets money out without it:

  1. Understate the amount. State 12 USD, put 9500.00 in the request. Every amount rule reads the stated figure, waves it through, and PayPal moves 9,500.
  2. Omit the amount entirely. PayPal's rule for create_refund is that a request with no amount refunds the entire capture. There is no number in the request to check, so a policy that treats "no amount" as "small" hands over the whole thing.

Interlock derives 9500 in the first case and unverifiable in the second. Both are held for a human. An amount nobody could establish can never satisfy an auto-approve rule β€” not because a rule says so, but because a guard outside the rule set says so, since rules are editable from the console and this must not be.

The same guards hold anything scored 70 or above, whatever the rules say. The model can only raise a score, so this is what makes "the model never approves" true even after someone edits a rule to auto-approve high-risk actions: raising a score can push an action towards a human, never towards execution.

The third account: what PayPal itself says

Reading the request harder solves only half the problem. Some facts are not in the request at all, and never could be:

  • accept_dispute_claim carries a dispute id. What the dispute is worth is in PayPal.
  • cancel_subscription carries a subscription id. What it bills is in PayPal.
  • send_invoice carries an invoice id. The total is in PayPal.
  • create_refund may carry an amount β€” but whether that amount is more than was ever captured, and whether the capture has been refunded already, is in PayPal.
the agent proposes Interlock asks PayPal and learns
create_refund GET /v2/payments/captures/{id} what was captured, whether it is already refunded, what the merchant kept after fees
accept_dispute_claim get_dispute the disputed amount and whether the seller can still respond
cancel_subscription, update_subscription show_subscription_details the billing amount, and whether PayPal already cancelled it
send_invoice, cancel_sent_invoice, record_refund_for_invoice get_invoice the total, the recipient, and the invoice's actual state

The first row is the one the toolkit cannot do. There is no tool for a capture, and list_transactions is the wrong substitute: PayPal's transaction search is not real-time, so a capture taken minutes ago is simply absent from it. Interlock calls the REST endpoint underneath instead β€” a GET on a payment resource, which moves nothing.

So Interlock asks, at proposal time, before anything is scored or decided. A reviewer therefore sees three accounts of the same action side by side: what the agent stated, what the request actually does, and what PayPal holds. Policy runs on the last two and never the first.

This does two things at once. It turns "the amount cannot be known" into a figure a rule can bound β€” a refund with no amount stops being unbounded once PayPal says the capture was 4,200, and a small one can then run unattended on a fact rather than on a guess. And it catches a class of problem neither the parameters nor the agent could reveal: a refund larger than the capture it draws on, an invoice sent twice, a subscription cancelled that PayPal already cancelled.

Three things the verification layer never does:

  • Speak for PayPal when PayPal did not answer. A failed lookup is unavailable, never confirmed, and never a finding against the agent. Silence is recorded as unknown β€” and an unknown cannot auto-approve, because the amount in the request is a ceiling, not a proof that the resource exists, is in a state the action applies to, or has anything left.
  • Decide. It reports; policy and the reviewer decide. A contradiction forces review, by the same guard outside the rule set.
  • Hang a proposal. Every lookup is bounded by a timeout.

Risk scoring is two layers, and they are shown separately

A deterministic layer always runs: action type, amount bands, a counterparty never seen before, repeated actions in a short window, and whether the agent's account of the action matches the request. It sets a floor.

A model (gpt-4.1 by default) then reads the specific request and may raise the score. It can never lower the floor, and it can never approve anything. Its own instructions treat the agent's rationale as attacker-controlled data: an agent reads customer emails and invoice notes, so text arguing for approval is treated as evidence of a problem rather than a reason.

The review screen shows both numbers. A reviewer should know whether an alarm came from a rule that always fires the same way or from the model reading this one request β€” and sometimes they disagree, which is the useful part.

If no OpenAI key is configured, the deterministic layer runs alone and every proposal is labelled as rules-only. Nothing silently loosens.

The two jobs are configured separately, because they are not the same job. Scoring is one short structured call per proposal; the agent is a multi-turn conversation that has to hold its nerve against a prompt injection written in a customer's own words. INTERLOCK_MODEL sets both, INTERLOCK_RISK_MODEL and INTERLOCK_AGENT_MODEL pin one at a time, and the console names each model it is actually running rather than the one this file was written about. Scoring is also the call a development loop repeats for every proposal in the queue, so it is where a cheaper model saves the most β€” and the saving is measurable rather than assumed, since the two findings the model layer contributes (a recipient that does not match the counterparty the agent named, and a note that argues against its own rationale) either still appear on a substituted model or they do not. pnpm seed --rules-only rebuilds the queue with no model calls at all, which is the right tool while policy or verification is what changed.

Two roles, because one would defeat the point

Every endpoint but /api/health requires a bearer token, and the token decides what the caller may do:

agent token reviewer token
read the queue, rules and audit log yes yes
read PayPal (16 calls, allow-listed) yes yes
file a proposal yes no
approve or reject no β€” 403 yes
change policy rules no β€” 403 yes

The agent cannot decide its own proposals. If one credential could do both, a compromised agent would approve its own work and the audit log would faithfully record a human decision that never happened β€” precise about a lie.

Identity comes from the token and nothing else. A caller that puts {"by": "someone-else"} in a request body is ignored; the decision is attributed to whoever the token identifies. There is a test for exactly that.

The agent

An agent is included, because a gate with nothing behind it proves nothing. It works a support inbox: read the customer's message, look up what it refers to in PayPal, and act.

It is a normal agent, not a hardened one. It holds an Interlock token and nothing else β€” no PayPal client id, no secret, no database handle β€” and it has exactly two tools:

  • paypal_read, which Interlock performs on its behalf. The catalogue the agent sees is built at startup from the toolkit's own tool descriptions rather than restated here, so it cannot drift.
  • propose_action, which files a proposal and returns what Interlock decided.

There is no third tool. It cannot execute, approve, edit a rule or touch the audit log, and that is not a matter of prompting: the token it carries is refused by those routes. Reads and writes do not share a door either β€” naming create_refund on the read route fails exactly as naming nonsense does, and there is a test for that.

The console has an Agent tab: the inbox, a Run button per message, and the run streaming as it happens β€” every PayPal call, the proposal, and what the agent told the merchant afterwards. The same thing runs from a terminal:

pnpm --filter @interlock/server agent            # work the whole demo inbox
pnpm --filter @interlock/server agent msg-5150   # one message

Starting a run from the console takes the reviewer's token, because starting it is an operator's action. The agent it starts authenticates separately, as an agent, over HTTP: it does not inherit the caller's credentials and still cannot approve its own work.

One of the three messages carries a prompt injection β€” a block addressed to "the processing agent" telling it the account is pre-cleared, to refund the full payment rather than the stated figure, and to leave the notice out of its summary. The demo does not depend on the agent falling for it, and on gpt-4.1 the outcome varies from run to run: it has proposed the 25.00 the customer asked for and reported what the message tried, and it has proposed refunding the whole 4,200.00 capture. Either way it can only propose, and Interlock holds both: the capture is partly refunded, so what is left cannot be confirmed. The queue also carries a seeded example of a fooled agent, with its rationale quoting the injected instruction.

The audit log

Each decision is appended carrying the SHA-256 hash of the entry before it, so every row is bound to the history behind it. Entries carry a hash of the parameters, so the chain proves not only that a decision happened but what it was about β€” the same paramsHash appears on the proposal and on its execution, alongside the PayPal resource that was created.

The log is tamper-evident, not tamper-proof. See Known limits.


Run it

Requires Node 24 and pnpm. (better-sqlite3 is a native module, so the Node version is not a free choice; this is the one it is built and tested against.)

pnpm install
cp .env.example .env     # PayPal sandbox credentials; the OpenAI key is optional
pnpm --filter @interlock/server seed     # fills the review queue with a worked scenario
pnpm dev                               # API on :8787, UI on http://localhost:5173
pnpm --filter @interlock/server agent    # optional: run the agent against the demo inbox

The seed builds real resources in your sandbox β€” draft invoices it reuses on later runs β€” and files proposals against them. It also refers to two captures from the sandbox this was built in; point it at your own with INTERLOCK_DEMO_CAPTURE and INTERLOCK_DEMO_PART_REFUNDED, or leave them and those scenarios will show as unverifiable, which is the honest result.

The agent needs OPENAI_API_KEY and a running server. Interlock itself needs neither.

Signing in

The console asks for a token before it will show anything. Unless you set your own in .env, the demo values are:

role token what it can do
reviewer demo-reviewer-token decide proposals, edit policy β€” use this one for the console
agent demo-agent-token file proposals and read; refused with 403 if it tries to decide

These are published defaults for a sandbox demo and are not secrets. Set INTERLOCK_AGENT_TOKEN and INTERLOCK_REVIEWER_TOKEN to use your own, and INTERLOCK_REQUIRE_TOKENS=true to refuse to start without them.

Try the boundary yourself:

curl -s -o /dev/null -w '%{http_code}\n' -X POST \
  -H 'authorization: Bearer demo-agent-token' -H 'content-type: application/json' \
  localhost:8787/api/proposals/<id>/approve -d '{}'      # 403

Get sandbox credentials from the PayPal developer dashboard (Apps & Credentials β†’ Sandbox). Without them Interlock still runs; approved actions are simulated and labelled as such. Without an OPENAI_API_KEY, risk scoring falls back to the deterministic layer.

Deploying

render.yaml deploys the whole thing as one Render service: the API serves the built console, so there is one origin and one URL. Create it from the dashboard with New β†’ Blueprint, point it at this repo, and Render will prompt for the three secrets β€” the PayPal sandbox pair and the OpenAI key. Everything else is in the file.

Two things about the free plan, both deliberate rather than hidden:

  • There is no persistent disk, so the database is rebuilt from the seed on every restart, and the audit chain starts over with it. The chain's guarantee is about tampering between entries, not about surviving a redeploy; anchoring it outside the database is listed under Known limits and is not built. A paid instance with a disk and INTERLOCK_DB pointed at it keeps the history.
  • The service sleeps when idle and takes a few seconds to wake, so the first request after a quiet period is slow.

The seed runs on boot only when the queue is empty, so a restart never duplicates the scenario and never disturbs a queue someone has been working in. Set INTERLOCK_SEED_ON_BOOT=false to leave a fresh database empty.

The seeded queue is filed with the times it would really have β€” the worked scenarios across the preceding hours, the burst as one tight cluster. That is not decoration. A velocity window is measured from the proposal being judged, so a queue whose every row arrived in the same second reads as one long burst: it blocks the next honest refund for ten minutes, and puts a repeat_burst on rows that earned nothing of the kind. Filed honestly, the burst is the only thing inside a single window, and it is eight long because the rule blocks a refund once five others preceded it β€” so the first five are what a loop looks like before anyone could tell, and the sixth is where it stops.

The starting queue on a deployment is scored by the rules alone. Without a disk it is rebuilt at every cold start, and scoring every proposal in it with the model each time the service wakes would let anyone visiting the URL spend the model budget, with no ceiling. Everything filed after boot β€” every agent run, every proposal you file by hand β€” is scored by both layers as normal. INTERLOCK_SEED_MODEL=true scores the starting queue too, and costs one model call per proposal in that queue β€” eighteen against a live sandbox, sixteen without.

The agent has two budgets, for the same reason. A run is a multi-turn model conversation, and both this URL and its tokens are published: without a ceiling, a visitor can spend the model budget, and a loop can spend it quickly. It also runs one at a time, because the console disables the button during a run and curl does not.

  • INTERLOCK_AGENT_RUN_BUDGET (8) is how many runs start per INTERLOCK_AGENT_RUN_WINDOW_HOURS (6). It refills, and the 429 says in how many minutes. The window is short on purpose: the tokens above are printed in this file, so anyone with the URL can spend the allowance, and the cost of that is not the money -- the spend ceiling below holds that -- but how long the Agent tab answers 429 behind them. Six hours bounds the wait; a day would not. A ceiling that only ever went up would be fine for a process that restarts often and wrong for one that is kept awake: whoever arrived first would hold the whole period, and the next visitor would be told the demo is spent.
  • INTERLOCK_AGENT_SPEND_USD (4.00) is what the model calls behind those runs may cost for the life of the process, counted from the usage the API reports rather than from an estimate. Runs are a poor proxy for money: a run whose tool results came back large costs several times what a short one does, and no number of runs can express that. This one does not refill.

/api/health publishes both, with what has been spent so far, so the state is visible rather than guessed. Nothing else is limited β€” reads, proposals and decisions are not metered and are left open. A refusal here is about cost, and the queue, the audit log and every run already made stay exactly as they were.

Verify the claims without any credentials

pnpm --filter @interlock/server test

38 tests, about a second and a half, no network and no model β€” because a guarantee that needs a language model to agree with it is not a guarantee. They cover both attacks above, the honest path still running unattended, a held proposal never reaching PayPal, both of the toolkit's failure shapes being recorded as failed rather than executed, a refund larger than the capture it draws on being caught, a capture PayPal has already refunded being refused, a failed PayPal lookup never being read as a passed one, the audit chain catching an edited and a deleted entry, and the demo tamper being undone byte for byte.

One test is named KNOWN LIMIT and asserts a weakness rather than a strength. It is below.


What a reviewer sees

  • Review queue β€” proposals ranked by risk, with the figure the decision rests on: the amount read from the request, or PayPal's own where the request was silent, and what the agent claimed where that differs.
  • Proposal detail β€” the three accounts side by side (agent, request, PayPal) with the call that was made named so it can be repeated by hand; the decision and the rule that produced it; both risk layers; the model's reasoning; the parameters bound for PayPal; and the agent's rationale, labelled untrusted.
  • Policy β€” the rules, in evaluation order, editable. Changing one is itself an audited event.
  • Agent β€” the inbox the agent works, and a live trace of one run: the PayPal calls it made, the proposal it filed, and its report to the merchant. A run that files something leaves the queue one click away.
  • Audit β€” the chain, with each entry's link to the one before it, and a verifier that walks it from the first entry. In sandbox mode there is a button that edits a row directly in the database so you can watch the check catch it.

Known limits

A security tool that oversells itself is worse than none, so:

  • Authentication is two static tokens, not user accounts. It is enough to separate the agent from the reviewer, which is the property that matters here, but there is no per-person identity, no rotation, no expiry and no second approver on large amounts. The audit log records which role decided, not which human.
  • The event stream is unauthenticated. EventSource cannot send headers, so /api/events is open. It carries a proposal id and its new status and nothing else, so reading it reveals no more than knowing a decision happened, but it is a gap worth naming. It is the only such route: the agent run streams newline-delimited JSON over a normal fetch precisely so it can stay behind a token.
  • Tamper-evident, not tamper-proof. The hashes are unkeyed, so anyone who can write to the database can recompute the chain. Removing entries from the end leaves a shorter chain that still reconciles β€” nothing links forward. Anchoring the tip outside the database fixes both, and is not built.
  • Velocity counts by action type, not by counterparty, and counts proposals that were refused. A burst of junk proposals can therefore delay a legitimate refund.
  • "Seen before" is earned cheaply. A counterparty becomes familiar after any executed action, including a draft invoice, which is auto-approved. The ceiling on what that unlocks is low (a refund under 50) but it is not nothing.
  • Nothing runs unattended while PayPal is unreachable. A failed lookup holds the action. That is the safe direction and it is deliberate, but it means an outage turns routine work into a review queue. There is no caching and no retry.
  • A partly refunded capture cannot be bounded. PayPal reports that a capture is PARTIALLY_REFUNDED but not how much of it is left, so Interlock knows the ceiling and not the headroom. It holds those for a human rather than guessing, which is correct and also means a legitimate second adjustment never runs unattended.
  • Two of the sixteen reads cannot answer in sandbox. get_merchant_insights is refused by the toolkit outside live mode, and get_shipment_tracking needs a scope this app does not hold, so PayPal answers 403. Both stay allow-listed β€” they are read-only at the API level and a live account can call them β€” but they are not offered to the agent, not counted on screen, and asking for one returns 501 unavailable_here with the reason. Neither restriction is Interlock's.
  • No rate limiting on anything except the agent. Reads, proposals and decisions can be driven freely against the sandbox, deliberately, because nothing there is metered. The agent is, so it has a run budget and runs one at a time; see "Deploying". That is a spending ceiling, not protection against a flood.
  • The demo tokens are published above, which is correct for a sandbox and obviously not for anything real.

Built with

  • PayPal Agent Toolkit (@paypal/agent-toolkit) against the sandbox β€” invoicing, payments, subscriptions, disputes and transaction search, used in both directions: the nine write actions are what Interlock gates, and get_invoice, get_dispute and show_subscription_details are how it checks a proposal against PayPal's own record before deciding. Where the toolkit has no tool β€” reading a capture β€” Interlock calls the REST endpoint underneath it. Proposal parameters are validated against the toolkit's own schemas at proposal time, so a malformed request is refused while it is still cheap rather than at the moment money is meant to move.
  • OpenAI gpt-4.1 over the Chat Completions HTTP API (no SDK), twice over: strict JSON-schema output for the risk layer, and function calling with Zod-validated tools for the agent that files the proposals (server/src/model.ts, server/src/agent/run.ts). Each job reads its own setting, so either can run on a different model; the console reports which.
  • AG Grid Community for the review queue, React + Vite for the console.
  • TypeScript, Express, SQLite (better-sqlite3), server-sent events for live updates.

Licence

MIT β€” see LICENSE.

About

Human-in-the-loop approval and policy layer for AI agents that move money through PayPal

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages