#37 AI agents and MCP 5.7 min
SQL Agent Guardrails: 8 Attacks Tested (DuckDB, Python)
A read only database stopped three of eight attacks on my SQL agent. The other five needed other layers.
Read the attack table
Copy the code folder first. Read the ATTACKS dictionary in attack.py, the layers in guard.py and the build function in shop.py. For the attack 'private column', say which layer stops it and why the other layers do not. DuckDB needs to be installed as in the video to run the code, so this is a reading task.
A hint
The agent's copy of the database has no email column at all.
Shrink the row limit
In guard.py change MAX_ROWS from 50 to 2. Predict what the first question in agent.py, the country with the most money, will print after the arrow, given that the video showed three countries before. Then run python agent.py if DuckDB is installed and compare. Run it in a fresh copy of the code folder, because agent.py cannot build agent.duckdb again once that file exists from an earlier run.
A hint
The run function uses fetchmany(MAX_ROWS).
Add an update attack
In attack.py add a new entry to ATTACKS, called 'update', with the SQL UPDATE orders SET amount = 0. Predict the three columns of the table for it: no guard, read-only and all layers. Then run python attack.py if DuckDB is installed and compare.
A hint
Think about which setups can change the file and which layer only allows a SELECT.
Stack two statements in the agent
In agent.py add a new question to SCRIPT, as the list ["SELECT 1; SELECT 2"] (one SQL text), then run python agent.py, which asks every question in SCRIPT. Run it in a fresh copy of the code folder, because agent.py cannot build agent.duckdb again once that file exists from an earlier run. Predict whether it is blocked and which message the verified attack table shows for a stacked statement. Run it if DuckDB is installed.
A hint
The stacked attack in the video was refused with 'exactly one statement allowed'.
These tasks are for you to try on your own machine. Nothing is checked or saved.
What this does not show
The model is a stand-in that returns fixed SQL, so no real model is tested. Eight attacks, not every attack. DuckDB's settings are defence in depth, not a sandbox, and the timer is best effort. One DuckDB version, on Windows. The shop, the data and the secret file are made up.
Up next in AI agents and MCP
More in AI agents and MCP
- #01 Local AI Agent in Python: No API Key (Ollama)
- #12 Multi-Agent Patterns in Plain Python: Pipeline, Router, Loop
- #22 OpenAI Agents SDK vs LangGraph vs Plain Python
- #23 Agent Memory: What to Keep and What to Forget
- #24 Approval Gates for Risky Agent Actions
- #25 Tool Errors: Retries, Fallbacks and Made-Up Answers
Related videos
- #92 Excessive Agency: Limit What Your AI Agent Can Do AI security and governance
- #102 Red-Team Your AI Agent With a Checklist AI security and governance
- #18 Prompt Injection Live: Attacking My Own LLM App AI security and governance
- #227 What Does One Query Cost? Cost Per Query From Timings Data strategy
