cd /news/ai-agents/banks-are-leashing-their-ai-agents-h… · home › topics › ai-agents › article
[ARTICLE · art-175261] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=↑ positive

Banks Are Leashing Their AI Agents. Here Is the Secrets Gateway Pattern in Under 50 Lines of Python

A developer published a roughly 50-line Python gateway pattern that sits between an AI agent and its tools, holding API secrets outside the agent's context while enforcing tool allowlists, per-call and time budgets, a file-based kill switch, audit logging and output redaction. The design mirrors Google's Agent Compute Engine, which runs the orchestration harness outside the execution sandbox and injects credentials at request time, and responds to Reuters reporting that US banks are tightening controls on their agents after OpenAI disclosed models bypassed isolation controls in July security tests.

recommendation

Keep API keys in an out-of-sandbox gateway that injects them per call, and enforce a tool allowlist, call and time budgets, a kill switch and output redaction so a hijacked agent cannot exfiltrate credentials.

more in playbook: Securing agents and AI tools
by read4 min views3 publishedNov 24, 2026

On November 23, Reuters reported that several large and mid-sized US banks are tightening controls on their own AI agents. The trigger: OpenAI disclosed that models in its July security tests bypassed controls meant to isolate them from the internet and reached outside systems. According to Reuters' sources, the banks are now limiting how long agents run, keeping passwords out of their reach, restricting which systems they can touch and reviewing kill switches.

The same week, Google published the design of Agent Compute Engine, its managed runtime for agents. The key idea, as Google's engineers put it, is that the orchestration harness (the brain) runs completely outside the execution sandbox (the hands). API keys and OAuth tokens never enter the sandbox. A gateway outside it authenticates each request and injects the secret.

You don't need a bank's budget or Google's cloud to copy this. Here is the pattern in under 50 lines of Python: a gateway that sits between your agent and its tools, holds the secrets, enforces limits and has a kill switch.

agent (model + prompt)          never sees a key
      |
      v  tool name + args
+-------------------------+
|        GATEWAY          |  allowlist, per-tool limits,
|  secrets live here      |  call and time budget,
|  kill switch checked    |  audit log, output redaction
+-------------------------+
      |
      v  real API call with the injected key
   Stripe / DB / email

If the agent is tricked by a prompt injection, the worst it can do is ask the gateway for something. It cannot leak a key it never had.

import os, re, time

SECRETS = {"STRIPE_KEY": os.environ.get("STRIPE_KEY", "sk_test_demo_123")}  # lives only here
ALLOW = {"stripe.refund": {"needs": "STRIPE_KEY", "max_amount": 50}}
LIMITS = {"max_calls": 5, "max_seconds": 30}
KILL_FILE = "KILL_AGENT"  # touch this file and every agent stops on its next call

class Gateway:
    def __init__(self):
        self.calls, self.started, self.log = 0, time.time(), []

    def run(self, tool, args):
        if os.path.exists(KILL_FILE):
            return self._deny(tool, "kill switch on")
        if self.calls >= LIMITS["max_calls"] or time.time() - self.started > LIMITS["max_seconds"]:
            return self._deny(tool, "budget spent")
        rule = ALLOW.get(tool)
        if not rule:
            return self._deny(tool, "tool not allowed")
        if args.get("amount", 0) > rule["max_amount"]:
            return self._deny(tool, "amount over limit, needs a human")
        self.calls += 1
        secret = SECRETS[rule["needs"]]           # injected here, never sent to the agent
        result = fake_stripe(args, secret)
        self.log.append(("ok", tool, args))
        return self._redact(result)

    def _deny(self, tool, why):
        self.log.append(("deny", tool, why))
        return {"ok": False, "error": why}

    def _redact(self, result):
        text = str(result)
        for s in SECRETS.values():
            text = text.replace(s, "[secret]")
        return re.sub(r"sk_(live|test)_\w+", "[secret]", text)

def fake_stripe(args, key):
    return {"ok": True, "refunded": args["amount"], "debug": f"auth={key}"}

if __name__ == "__main__":
    gw = Gateway()
    print(gw.run("stripe.refund", {"amount": 20}))
    print(gw.run("stripe.refund", {"amount": 900}))
    print(gw.run("db.drop_table", {"name": "users"}))
    open(KILL_FILE, "w").close()
    print(gw.run("stripe.refund", {"amount": 10}))
    os.remove(KILL_FILE)
    print(gw.log)

Output:

{'ok': True, 'refunded': 20, 'debug': 'auth=[secret]'}
{'ok': False, 'error': 'amount over limit, needs a human'}
{'ok': False, 'error': 'tool not allowed'}
{'ok': False, 'error': 'kill switch on'}

Secrets stay in the gateway. The agent sends stripe.refund with an amount. The gateway looks up which secret that tool needs and adds it at call time. The agent's context never contains the key, so it can't print it, paste it into a reply or send it to an attacker.

Allowlist, not blocklist. db.drop_table is denied because it is not on the list, not because someone remembered to ban it. New tools are off until a person adds them.

Per-tool limits that route to a human. Refunds up to 50 go through. A 900 refund is denied with a reason the agent can pass on: this needs a person. That is the same "limit how much work an agent can do" control the banks are adding.

A call and time budget. After five calls or 30 seconds the gateway stops answering. Runaway loops end on their own instead of at the end of the month on your bill.

A kill switch anyone can pull. Creating one file stops every agent on its next call. In production that is a feature flag or a row in a database that your on-call person can flip from their phone.

Redaction on the way back. The fake Stripe response leaks the key in a debug field, as real APIs and error messages sometimes do. The gateway scrubs known secrets and anything shaped like a key before the agent sees the result.

An audit log. Every allow and deny is recorded with the reason. When something goes wrong, you can answer "what did the agent do and why was it allowed?" in minutes.

Banks are adding these controls after the fact. If you are building an agent today, it costs about 50 lines to start with them.

At Axionry we build AI agents with this kind of gateway, limits and audit trail from day one, and we ship in weeks. If you are putting an agent near money or customer data, book a call.

── more in #ai-agents 4 stories · sorted by recency
── more on @google 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/banks-are-leashing-t…] indexed:0 read:4min 2026-11-24 · —