Guardrails for AI Coding Agents: Budgets, Blocklists and Human Approval (with an Open-Source MCP Example)
A practical, honest guide to securing AI coding agents that use the Model Context Protocol (MCP): least privilege, approvals, spend caps, sandboxes β and what a small open-source policy gate like AegisMCP can and cannot do.
Disclosure: AegisMCP is an open-source prototype built by the founder of Algoroasts. We describe exactly what its current code does β including its limits β so you can judge it fairly. We earn nothing from it.
AI coding assistants that speak the Model Context Protocol (MCP) can now read files, run terminal commands and call APIs on your behalf. That is powerful, and it changes the security question from "is the model's answer correct?" to "what can this agent do if it is wrong β or if someone tricks it?"
Key takeaways
- Prompt injection is the #1 risk in the OWASP Top 10 for LLM Applications 2025; runaway cost (unbounded consumption) is #10.
- The strongest control is least privilege: expose the fewest MCP tools and folders the task needs.
- Require a human click for destructive actions, and enforce budgets outside the model, not in the prompt.
- Regex blocklists are a useful tripwire but trivially bypassed β combine them with sandboxes and approvals.
- AegisMCP is a small MIT-licensed MCP server that demonstrates a blocklist plus a spend ledger; it is a learning example, not a complete firewall.
The two failure modes that matter
1. The agent does something destructive. A model can misread an instruction, or follow instructions hidden inside a file, web page or dependency it was asked to read (indirect prompt injection). If the agent has a shell, "clean up the build folder" and "delete the repo" are one bad path away.
2. The agent burns money. Agents loop. A tool call that fails, retries and re-plans can run for hours against a paid API. OWASP files this under unbounded consumption: the cost is real even when nothing is "hacked".
Controls, from strongest to weakest
| Control | What it stops | Bypass risk |
|---|---|---|
| Least privilege (only the tools and folders a task needs) | Most damage, by removing the capability | Low |
| Sandboxing (container, VM or throwaway workspace) | Damage to your real machine and secrets | Low |
| Human approval for writes, deletes, deploys and payments | Destructive actions slipping through | Low, if you actually read the request |
| Spend caps enforced by the API provider or a proxy | Runaway cost | Low |
| Allowlists of permitted commands | Unexpected commands | Medium |
| Blocklists / pattern matching | Known-bad strings | High β easy to rephrase or encode |
The pattern is clear: controls that remove capability beat controls that try to recognise bad intent. A model cannot delete a folder it was never given access to.
A minimal policy gate: how AegisMCP works today
AegisMCP is a small monorepo with an MCP server (stdio transport) and a Next.js dashboard. Its current server code is short enough to describe completely:
- It registers one tool,
secure-execute, which takes a text payload. - Each payload is checked against a blocklist of three patterns:
rm -rf,chmod 777and the phrase "ignore previous instructions". A match returns a "SECURITY HALT" error. - Each allowed call is charged a flat notional cost (USD 0.005, multiplied by a 1.30 markup) against a daily budget ledger (USD 5.00 by default) stored in a local JSON file. When the ledger is full, calls return "FINANCIAL HALT".
What that means in practice:
- It guards only the calls an agent sends through its own tool. It does not sit in front of your agent's other MCP servers or built-in tools, so it is not a transparent firewall for everything Claude Desktop or Cursor can do.
- The cost figure is a fixed estimate per call, not a measurement of real token usage.
- Three regex patterns are a demonstration, not coverage:
rm -rfwith two spaces, a script file, or base64 would pass.
That makes it a good, readable starting point for learning how an MCP policy gate is wired β and a reminder of why the stronger controls above matter.
Trying it locally
git clone https://github.com/thekartikeyamishra/AegisMCP.git
cd AegisMCP
npm install
npm run devThen register the server in Claude Desktop's claude_desktop_config.json (macOS: ~/Library/Application Support/Claude/claude_desktop_config.json; Windows: %APPDATA%\Claude\claude_desktop_config.json), pointing at the built CLI:
{
"mcpServers": {
"AegisFirewall": {
"command": "node",
"args": ["/absolute/path/to/AegisMCP/packages/cli/dist/index.js"]
}
}
}Restart the app after editing the file. Cursor and other MCP clients accept the same command + args pair in their MCP server settings.
A sensible setup for real projects
- Start read-only. Give the agent read access to the project folder only. Add write access per task.
- Never mount your home directory, SSH keys or
.envfiles. Use a dedicated workspace or container. - Keep approvals on for shell commands, file deletion, git push and anything that costs money.
- Set a hard monthly limit in your AI provider's billing console β that limit holds even if every other layer fails.
- Log every tool call so you can see what happened after the fact.
- Add pattern checks last, as an extra tripwire, not as the wall.
If you build AI features for EU users, these controls also map onto the record-keeping and human-oversight themes in our EU AI Act guide for developers.
Frequently asked questions
What is the biggest security risk with AI coding agents?
Prompt injection β instructions hidden in content the agent reads β ranked first in the OWASP Top 10 for LLM Applications 2025. Combined with broad tool access, it can turn a helpful agent into a destructive one.
Can a regex blocklist make an AI agent safe?
No. Blocklists catch known strings but are easy to evade by rephrasing, spacing or encoding a command. Use least privilege, sandboxes and human approval first, and treat pattern matching as an extra tripwire.
How do I stop an AI agent from running up a huge API bill?
Set a hard spending limit in your AI provider's billing settings, add per-task budgets in any proxy you control, and watch for loops in your logs. Limits enforced outside the model are the ones that hold.
Does AegisMCP protect all of Claude Desktop's or Cursor's tools?
Not in its current version. It is an MCP server exposing a single guarded tool with a three-pattern blocklist and a flat-cost budget ledger. It only checks calls routed through that tool.
The safest agent is the one that simply cannot reach what you can't afford to lose. Remove capabilities first, add approvals second, and treat clever detection as a bonus.
Sources
Continue your decision path
AI Agent Developer in India 2026: The Newest High-Leverage Specialization
What AI agent development is, why it is a high-leverage specialization for Indian developers in 2026, and the build-first path to mastering it.
The EU AI Act for Developers in 2026: What You Actually Need to Know
A developer-focused 2026 guide to the EU AI Act β the phased timeline, risk tiers, what high-risk obligations mean in code, and how to prepare.
EU AI Engineer Skills Roadmap for 2026: Build for a Regulated Market
A 2026 skills roadmap for AI engineers targeting the EU β the core production-AI competencies plus the AI Act and GDPR knowledge that EU employers specifically need.
GDPR and Privacy Engineering in 2026: A High-Value Developer Skill in the EU
Why privacy engineering is a valuable EU developer skill in 2026, how GDPR and the AI Act intersect, and the concrete skills that make you the compliance-capable engineer.