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. 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. python 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 https://axionry.com/services/ai-product-development 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 https://axionry.com/book .