Kick off your book project in 2 hours, get started with GhostAI in 2 hours, or do both! Free live workshops, on Zoom. You’ll leave with a real book project and a clear plan to keep going. Saturday, June 27, 2026.

Leanpub Header

Skip to main content

AI Security for Developers

Protecting Code in the Age of Agents

45% of AI-generated code has vulnerabilities. This book covers prompt injection, data leakage, secure coding with AI tools, MCP server hardening, agent sandboxing, supply chain security, and OWASP LLM compliance. 14 chapters with attack demos

and defense code.

Minimum price

$9.00

$15.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
WEB
About

About

About the Book

45% of AI-generated code contains security vulnerabilities. Your team is shipping AI-assisted code every day. Are you checking it?

AI changed the attack surface. Prompt injection, data leakage, model extraction, supply chain poisoning — these are threats that didn't exist five years ago. Traditional AppSec isn't enough anymore.

This book bridges the gap between AI capabilities and security engineering:

- The new attack surface: why AI systems need different security thinking

- How AI-generated code introduces vulnerabilities — and how to catch them automatically

- Prompt injection: the attack taxonomy, real-world examples, and why there's no easy fix

- Data leakage: training data memorization, context window exposure, model extraction

- Building automated security pipelines for AI-generated code (SAST, DAST, custom rules)

- Secure coding practices with Copilot, Cursor, and Claude Code

- Input validation and output sanitization for AI systems

- Authentication and authorization for AI agents (principle of least privilege)

- Securing MCP servers: transport security, tool access control, production hardening

- Sandboxing AI agents in production: network isolation, resource limits, audit trails

- Supply chain security: model provenance, dependency risks, SBOM for AI

- Monitoring and incident response for AI systems

- Compliance: OWASP LLM Top 10, EU AI Act, SOC 2 implications

- Building a security-first AI practice: culture, training, threat modeling

14 chapters with Python code showing both attacks and defenses. Written for developers and security engineers who need to secure AI-powered applications today, not tomorrow.

Author

About the Author

CAIO INCAU

aio Incau é Engineering Manager com experiência liderando times de engenharia de software em larga escala. No dia a dia, combina gestão de pessoas com profundidade técnica para entregar produtos que impactam milhões de usuários. Começou a usar Claude Code por curiosidade, virou adepto por produtividade, e escreveu este livro para que outros desenvolvedores não precisem descobrir tudo sozinhos.                

                                                                                                                              

Contents

Table of Contents

Getting Started

  1. Unsure How to Get Started? Try our Book Workshop!
  2. How to Write on Leanpub
  3. Previewing and publishing
  4. Basic formatting
  5. Markdown and Markua
  6. Generate a preview version of your book
  7. Either read a tutorial, or just go for it!
  8. Thanks for being a Leanpub author!

Writing in Markua

  1. Section One
  2. Including a Chapter in the Sample Book
  3. Links
  4. Images
  5. Lists
  6. Page Breaks
  7. Code Samples
  8. Tables
  9. Math
  10. Headings
  11. Block quotes, Asides and Blurbs
  12. Good luck, have fun!
  13. author: Caio Incau date: “2026-05-25T13:41:16Z” identifier: “urn:uuid:9224380c-44fa-4fba-a29b-526741c89a23” language: en title: AI Security for Developers

Preface

  1. Who this book is for
  2. How this book is organized
  3. What you need

Chapter 1 —- The New Attack Surface

  1. The pre-AI security model
  2. What AI changes
  3. The new threat categories
  4. Why traditional AppSec is not enough
  5. A defense-in-depth model for AI
  6. Common mistakes
  7. Exercises
  8. Summary

Chapter 2 —- How AI-Generated Code Introduces Vulnerabilities

  1. Why AI writes insecure code
  2. The vulnerability taxonomy
  3. Measuring your exposure
  4. The trust calibration problem
  5. Common mistakes
  6. Exercises
  7. Summary

Chapter 3 —- Prompt Injection: The SQL Injection of AI

  1. How prompt injection works
  2. The attack taxonomy
  3. Why there is no parameterized query equivalent
  4. Building layered defenses
  5. Common mistakes
  6. Exercises
  7. Summary

Chapter 4 —- Data Leakage and Model Extraction

  1. Training data memorization
  2. Context window exposure
  3. Model extraction attacks
  4. Practical data loss prevention for AI
  5. Common mistakes
  6. Exercises
  7. Summary

Chapter 5 —- Securing AI-Generated Code

  1. Static analysis for AI-generated code
  2. Building the CI/CD security gate
  3. GitHub Actions integration
  4. Automated fix suggestions
  5. Common mistakes
  6. Exercises
  7. Summary

Chapter 6 —- Secure Coding with AI Assistants

  1. Security-aware prompting
  2. The security review checklist for AI code
  3. Configuring AI assistants for security
  4. The review workflow
  5. Common mistakes
  6. Exercises
  7. Summary

Chapter 7 —- Input Validation for AI Systems

  1. Input validation architecture
  2. Pre-model input filters
  3. Runtime guardrails
  4. Output sanitization
  5. Putting it all together
  6. Common mistakes
  7. Exercises
  8. Summary

Chapter 8 —- Authentication and Authorization with AI

  1. The agent authentication problem
  2. OAuth 2.0 for AI agents
  3. API key management for AI services
  4. The principle of least privilege for AI agents
  5. Middleware for AI endpoint protection
  6. Common mistakes
  7. Exercises
  8. Summary

Chapter 9 —- Securing MCP Servers

  1. The MCP security model
  2. Server hardening
  3. Transport security
  4. Production deployment patterns
  5. Common mistakes
  6. Exercises
  7. Summary

Chapter 10 —- Securing AI Agents in Production

  1. The agent threat model
  2. Sandboxing agent execution
  3. Network isolation
  4. Resource limits and quotas
  5. Comprehensive audit trails
  6. Putting it all together: the secure agent runtime
  7. Common mistakes
  8. Exercises
  9. Summary

Chapter 11 —- Supply Chain Security for AI

  1. Model provenance
  2. Dependency risk management
  3. Third-party model evaluation
  4. AI Software Bill of Materials (AI-SBOM)
  5. Common mistakes
  6. Exercises
  7. Summary

Chapter 12 —- Monitoring and Incident Response

  1. What to monitor
  2. Building the monitoring pipeline
  3. Detection rules
  4. Incident response playbooks
  5. Forensic analysis
  6. Common mistakes
  7. Exercises
  8. Summary

Chapter 13 —- Compliance and Regulatory Requirements

  1. OWASP Top 10 for LLM Applications
  2. EU AI Act security requirements
  3. SOC 2 implications for AI
  4. Automated compliance evidence collection
  5. Common mistakes
  6. Exercises
  7. Summary

Chapter 14 —- Building a Security-First AI Practice

  1. The DevSecAI workflow
  2. Threat modeling for AI systems
  3. Security training program
  4. The security champion model
  5. Security metrics and reporting
  6. Common mistakes
  7. Exercises
  8. Summary

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.)

In fact, authors have earned over $15 million writing, publishing and selling 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.

Learn more about writing on Leanpub