Your Agent Just Did What?
Kill switches, guardrails and audit trails for AI agents in production
Your AI agent can follow the wrong instruction, expose customer data, issue duplicate payments or execute an action nobody authorised.
A prompt won't reliably stop it.
This hands-on Python engineering handbook shows you how to build the runtime controls that do: least-privilege permissions, policy enforcement, human approval, kill switches, tamper-evident audit trails and safe recovery.
Build one runnable reference agent, attack it with seven scenarios, and see what happened when two real language models were put through the same tests.
Stop trusting agents to behave. Build systems that control what they can do.
About
About the Book
In July 2025, an AI coding agent deleted a company's production database during a code freeze. The instruction not to make changes was in its prompt. It didn't matter.
A prompt is a request, not a control. This book shows you how to build the controls that actually hold, whatever the model decides: the agent can only propose an action, and your runtime decides whether it happens.
You build them one chapter at a time, on a single runnable reference agent in Python: a refund agent for an online shop, attacked seven different ways and then fixed.
Stop. Kill switches that pause, terminate, revoke credentials, isolate and recover, so nothing runs after you press stop.
Limit. Least privilege, single-use credentials, purpose-bound data access, budgets and loop detection.
Prove. Hash-chained audit trails that show who acted, under which rule, and who approved it.
Recover. Idempotency keys and a side-effect ledger, so a retry never pays a customer twice.
Every claim is either sourced or tested, and every test can be repeated. Some of what the tests found:
- Without controls, an agent on a refund spree paid 191.66 on a 120.00 order. With them, nothing ran after the stop.
- When the payment provider lost two responses, an uncontrolled agent paid three times. Through the gateway, it paid once.
- On two real models, a stronger model was not a safe one. DeepSeek ignored every hidden instruction, yet still handed another customer's email to the wrong person in 2 of 5 runs without controls. Through the gateway, no data left the system in any run on either model.
You also get human approval with four eyes and delegated limits, defences against prompt injection at the tool boundary, safe multi-agent delegation, and a test suite you can run against your own models. The final chapters map every control to the EU AI Act, GDPR and NIST AI RMF, and to data protection law in Nigeria, Kenya and South Africa, then show how to govern a whole fleet of agents.
Eight appendices give you templates, schemas, checklists and the full test records.
For engineers and tech leads who have already built an agent and now need to make sure it can't do something it was never authorised to do.
Feedback
Packages
Pick Your Package
All packages include the ebook in the following formats: PDF
The Book
Minimum price
Suggested price$29.00$19.00
The Book + Code
Minimum price
Suggested price$39.00The complete book plus the runnable reference agent in Python: source code, policy files, 103 tests and the 7-scenario attack suite. Run every result in the book yourself, then adapt the controls to your own agents.
$29.00
- Reference Code
Author
About the Author
Oluwajuwon Omotayo is a software engineer, AI product builder and the CEO of Ginux Technologies Limited in Lagos, Nigeria. He has designed and built production systems across artificial intelligence, SaaS, cloud infrastructure, fintech and IoT.
His recent work focuses on one problem: AI agents can now take real actions, but the systems around them often can't limit, stop or explain those actions. He built Comply54, an open-source layer that checks an AI agent's tool calls against regulations such as Nigeria's NDPA, Kenya's Data Protection Act and South Africa's POPIA before they run. He also wrote the research paper "The Enforcement Gap: Why Africa's AI Regulations Need Runtime Enforcement" (SSRN, 2026), and contributed a Nigerian policy pack to Microsoft's Agent Governance Toolkit.
His work spans backend engineering, system architecture, developer tools, computer vision and open-source software. He is particularly interested in how complex systems behave in real-world environments, and he enjoys helping developers understand the principles behind the tools they use.
His books put that into practice. Home Cameras You Can Trust helps readers build reliable home surveillance with Frigate NVR. Your Agent Just Did What? shows engineers how to stop, limit and audit AI agents in production, built on a runnable reference agent and tested against real models.
His approach to technical writing is simple: explain the concepts, demonstrate the implementation, share what works, and be honest about what doesn't.
Contents
Table of Contents
- About this book and the reference agent
- Why prompts aren't security controls
- Threat modelling an AI agent
- Agent identity and least privilege
- Purpose-bound access and data permissions
- Runtime policy enforcement: allow, deny or approve
- Human approval and delegated authority
- Kill switches, revocation and containment
- Prompt injection and the tool boundary
- Multi-agent delegation and permission inheritance
- Audit trails and decision provenance
- Observability, budgets and runaway execution
- Testing guardrails and security regression
- Idempotency, retries and side-effect recovery
- Mapping controls to regulatory frameworks
- African data protection and AI governance
- Governing an agent fleet
Appendices: A. The reference agent, file by file · B. The runtime policy engine · C. Permission and tool inventory template · D. Human approval, implemented · E. Audit event schema · F. Kill-switch and incident response checklist · G. Agent security test cases and test records · H. Regulatory control mapping
Get the free sample chapters
Click the buttons to get the free sample in PDF or EPUB, or read the sample online here
The Leanpub 60 Day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms...
Earn $8 on a $10 Purchase, and $16 on a $20 Purchase
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
Write and Publish on Leanpub
You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!
Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.
Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.