← All posts
aipythonsecurityllm

I gave my AI agent database access. Then I built a firewall so it couldn't wipe prod.

A few months ago I gave an autonomous agent write access to a real database. It was a LangChain-style loop (plan, call a tool, observe, repeat), and one of the tools ran SQL.

It worked great in the demo. Then I watched it, during a "clean up the test rows" task, generate this:

DROP TABLE users;

It didn't run (staging, and I was watching). But the lesson landed: the LLM doesn't know the difference between a destructive command and a safe one until it's already calling the tool. And by then your code is one cursor.execute() away from an incident.

"AI firewalls" guard the wrong side

When I went looking for protection, almost everything in the "LLM security" space guards the inbound side (prompt injection, jailbreaks, PII in the input). Useful, but it's the wrong end for an autonomous agent. My problem wasn't a malicious prompt. It was a well-meaning agent emitting a catastrophic action.

What I actually wanted was a firewall on the outbound side, the tool calls themselves:

  • destructive SQL (DROP TABLE, unscoped DELETE)
  • writes to prod / ALTER ... DROP COLUMN
  • SSRF and cloud-metadata fetches (169.254.169.254)
  • bulk secret / API-key reads
  • runaway retry loops draining your token budget

And critically: I wanted the catch to be deterministic. If your safety layer is itself an LLM call, it's slower, costs money, and can be talked out of it. A DROP TABLE should be blocked by a rule, not a vibe.

The 2-minute version you can run right now

I ended up building this and putting the SDK on PyPI. Here's the whole thing. It blocks a live DROP TABLE offline, with no API key, using built-in policy seeds:

pip install agentx-security-sdk
from agentx_sdk import agentx_protect, is_block

@agentx_protect(agent_id="demo")
def run_sql(query: str, db_session=None):
    print("EXECUTED (DANGER):", query)   # never reached
    return {"ok": True}

result = run_sql(query="Please clean up: DROP TABLE users;")
print("BLOCKED:", is_block(result))       # -> True, offline, no key

One decorator on your tool function. The destructive call gets intercepted before your function body runs, and you get a block result back instead of a smoking crater. No gateway, no account, no LLM in the hot path for this, and it runs entirely on your machine.

Note: the package is agentx-security-sdk (import path agentx_sdk), version >= 0.3.11.

How the block works

The decorator wraps your tool call and runs the arguments through a layer of deterministic checks before execution: pattern and structural rules for the known catastrophic shapes (destructive SQL, prod writes, SSRF targets, secret-store reads, no-progress loops). If a rule trips, the call returns a block instead of executing. No model inference required for the floor, which is why it works with no key and adds negligible latency.

There's more above that floor. It can escalate ambiguous-but-dangerous actions for a human-in-the-loop decision, circuit-break a runaway loop, and (with a key) attempt to reframe and retry the run instead of just dying. But the part I want you to be able to verify in 2 minutes without trusting me is the deterministic block above. That's the whole point of leading with it.

Why I'm posting this

I'm looking for a handful of people running real Python agents (something that touches a live DB, cloud, files, or money, ideally unattended) to try it against their actual stack and tell me where it's wrong. Not a launch, not a sales pitch. I want to know:

  • Does it catch the thing that would've bitten you?
  • What dangerous action shape is it missing?

If you've ever thought "what happens when this agent does something irreversible at 2am," I'd genuinely like your eyes on it.

  • Try it live (keyless quickstart): agentx-core.com
  • Community / tell me what broke: Discord
  • Bring the war story that made you click.

If your agent never touches anything irreversible, ignore me. If it does, the repro is two minutes, and DROP TABLE is a bad way to find out the hard way.

See it catch and recover, live

Paste a tool call you are worried about and watch AgentX block it, coach the agent, and let the run finish. No install, no key.

Open the playground

This piece is also syndicated on dev.to.