Secure AI Code: How Teams Ship AI-Written Code Safely
AI coding agents pass tests but often ship vulnerabilities. See what the research shows and the controls enterprise teams use to secure AI-generated code.
On this page
AI-written code is not secure by default, and passing tests does not change that. The way to secure AI code is to treat every AI-generated change like any other change: specify the security requirements, review it independently, scan it, and keep evidence of who approved what. Vera, our free code review agent, shows the evidence behind each finding and re-checks fixes, and VibeFlow runs the delivery process around it.
TL;DR
- AI agents often produce code that works but is not secure: in one 2026 benchmark the strongest agent was both functional and secure on only 25.1% of tasks.
- Developers using an AI assistant wrote less secure code and were more confident in it, so confidence is not a control.
- Apply the same gates (review, SAST, DAST, dependency scanning, secret scanning) to AI code as to human code, scaled to the risk of the change.
- Control the tools: allowlist them, sandbox agents, and route package installs through an approved registry.
- Keep evidence for every accepted change: what changed, why, which checks ran, the results and the approver.
What the evidence says about AI-generated code
The Last Secure Code Benchmark (October 2026) built 450 tasks from 150 real vulnerabilities across seven languages. Across six frontier agents, 73.6% to 91.3% of tasks passed functionally. Yet the strongest, Claude Fable 5, produced code that was both functional and secure for only 25.1% of tasks. Weaknesses whose defense depends on a policy the specification never states, such as which data a response may reveal, were almost never secured by any model.
That gap explains why green test runs mislead. Tests check behavior. They rarely check what an attacker would do.
Humans are part of the problem too. A Stanford user study found that participants with an AI assistant wrote significantly less secure code and were more likely to believe it was secure.
In real repositories, an analysis of 733 AI-generated snippets in GitHub projects, from GitHub Copilot, CodeWhisperer and Codeium, found security weaknesses in 29.5% of Python and 24.2% of JavaScript snippets, spread across 43 CWE categories. A CWE (Common Weakness Enumeration) is a standard label for a type of software flaw, such as CWE-79 for cross-site scripting.
Common failure modes
The EU’s cybersecurity agency lists the non-adversarial ways AI-assisted development goes wrong in its September 2026 draft technical advisory:
- Output that is functional but insecure
- Unintended actions or side effects
- Incomplete context, unclear instructions or incorrect assumptions
- Hallucinated or outdated suggestions
- Lack of understanding or review of generated changes
- Weak tests, review or evidence
A systematic review adds that models can reproduce insecure patterns from training data, invent APIs or security routines, and write patches that only partly fix a vulnerability or introduce a new one.
Dependencies are a specific risk. A USENIX Security 2025 study generated 576,000 Python and JavaScript code samples with 16 models, and a 2026 supply-chain analysis of it reports that 19.7% of the recommended packages did not exist. Attackers can register those invented names with malicious code, an attack called slopsquatting. Every new dependency an agent adds needs a check.
For a wider view of how these risks map to agent behavior, see our CISO guide to AI agent threat models. Teams also run into process failures when automating without clear ownership; this overview of AI automation mistakes to avoid covers several.
A four-step routine for securing AI code
ENISA’s advisory frames the work as four actions: identify the security expectations, specify them to the agent, verify the output in proportion to risk, and record evidence. Here is that routine step by step, with where it usually breaks.

1. Identify the security expectations
List what applies to the component: authentication rules, data handling, logging, licensing, the frameworks you answer to. The benchmark finding on unstated policies is the reason this comes first. An agent cannot meet a requirement it was never given.
Where it goes wrong: requirements live in a security wiki, not in the repository the agent reads.
2. Specify them to the agent
Put the requirements into reusable skills and project instructions so every task starts with them. Restrict what the agent can reach. The OWASP Secure Coding with AI cheat sheet calls for running agents in sandboxed environments, using tool allowlists, and weighing the risk of auto-accept modes that bypass confirmation prompts. Our guides on Model Context Protocol and how agents use MCP tools explain how tool access works, and the MCP Gateway page covers governing it.
Where it goes wrong: every developer configures their own agent and tool list, so nobody knows which tools touched which code.
3. Verify with review and security checks
The CD Foundation CI/CD Cybersecurity Guide says AI-generated changes belong inside your existing source code management, peer review, static analysis, dependency scanning and vulnerability management workflows. ENISA adds code review, testing, SAST, DAST and dependency scanning, with review depth proportionate to the sensitivity of the component, the scope of the change and the autonomy given to the agent.
Three practices matter most:
- Test adversarially. The OWASP cheat sheet recommends negative tests the AI did not write, and hand-written tests for authentication, authorization, input validation and cryptography. Measure confidence by adversarial results, not by whether everything passed.
- Use a second reviewer. In the benchmark, pooling six models secured 44.0% of tasks versus 25.1% for the best single model, and 56.0% were secured by none. Different models catch different flaws, so an independent reviewer beats self-review.
- Scan the same way for all code. Secret scanning and SAST thresholds apply regardless of who or what wrote the change.
Where it goes wrong: the agent that wrote the code also reports that checks passed. ENISA says statements such as “all checks passed” should not be accepted unless they are linked to supporting evidence.
Vera is built for this step. Each finding names the trigger down to the file and line, explains the impact, and shows the evidence and the commands used to verify it. When your coding agent fixes a blocker, Vera re-checks the fix on the same pull request, and repeat reviews stay within a round budget. See how it works on the Vera AI code review page, or read the five stages of an AI code review agent and our piece on automated quality gates.
4. Record evidence
ENISA says evidence should show what changed, why, which checks ran, their results and who approved, moving toward SBOM updates, signed provenance records and machine-readable attestations in CI/CD. An agent can help collect and format that evidence, but ENISA is clear that it should not replace the underlying checks or the human decision to accept the change.
Where it goes wrong: evidence is assembled by hand before an audit, from chat logs and memory. Process documentation is easier to defend when it is captured as work happens, as in this guide to SOPs that pass NIST and ISO checks. In VibeFlow, every task is traced to a git commit with line counts, so the record exists when the auditor asks.
Controls for dependencies and data
The supply-chain analysis cited above, last reviewed in October 2026, recommends three controls for AI coding assistants:
- Route package installs through an internal registry proxy with an allowlist or quarantine period for new packages.
- Use lockfiles with hashes, and fail the build on any unreviewed new dependency.
- Set an enterprise policy for which assistants and models are approved, what data they may see and how prompts are logged.
Prompts and context can also leak sensitive data. This breakdown of LLM data leakage attack surfaces helps you decide which data your agents may see. Measuring unsanctioned tool use is a related step, covered in Shadow AI in your SDLC.
Which standards apply
For US teams, NIST SP 800-218 (the Secure Software Development Framework, or SSDF) is the baseline. NIST SP 800-218A, final since 26 July 2024, is an SSDF community profile for generative AI and is used alongside it. SP 800-218 Rev. 1 (SSDF version 1.2) was released as an initial public draft on 17 December 2025, and a summary of the SSDF notes it was still a draft in October 2026, so check NIST for the current status.
For agentic coding assistants specifically, Singapore’s Cyber Security Agency published a Security Assessment Handbook in October 2026. It explains how IDE-based and CLI-based assistants connect to external tools, maps threats and attack paths across trust boundaries, and tiers mitigations by criticality. Our compliance overview explains how these frameworks fit together.
One platform instead of three tools
Most teams adopting AI coding end up with a tracker, an AI reviewer and a compliance add-on. Axiom Studio ships these as one platform. VibeFlow supplies a team of nine specialist agent personas across planning, development, security, QA and delivery, and tracks features, todos and issues in one dashboard. Vera reviews the output, and in VibeFlow the same work item also passes Security Lead and QA Lead review before it ships. Shared context means the reviewer sees the same ticket, plan and change the agent worked from.
Plans are listed on the pricing page: Starter (free), Pro at $20 per month, Team at $49 per seat per month with a three-seat minimum, and Enterprise. Vera is free on every plan, with unlimited reviews and users.
For a deeper look at how autonomous agents write and ship code, read what agentic coding is.
Sources
- Last Secure Code Benchmark: Is the Code You Vibe Secure? (arXiv, October 2026)
- Do Users Write More Insecure Code with AI Assistants? (Perry et al., CCS 2023)
- Security Weaknesses of Copilot-Generated Code in GitHub Projects: An Empirical Study (ACM TOSEM)
- ENISA Technical Advisory on AI-assisted software development (draft, September 2026)
- Security in LLM-Assisted Coding: A Systematic Literature Review (arXiv, October 2026)
- We Have a Package for You! A Comprehensive Analysis of Package Hallucinations by Code Generating LLMs (USENIX Security 2025)
- Enterprise Software Supply Chain Security and AI Code Risk (October 2026)
- CD Foundation CI/CD Cybersecurity Guide: AI-Assisted Code Development
- Secure Coding with AI, OWASP Cheat Sheet Series
- NIST SP 800-218A: Secure Software Development Practices for Generative AI and Dual-Use Foundation Models (July 2024)
- NIST SP 800-218 Rev. 1, SSDF Version 1.2 (Initial Public Draft, December 2025)
- NIST SSDF (SP 800-218) Guide
- Security Assessment Handbook for Agentic AI Coding Assistants (CSA Singapore, October 2026)
Recommended
- Quality Gates for AI-Generated Code: Automated Review and Compliance
- CISO Guide to AI Agent Security: Threat Models for Code Agents
- Anatomy of an AI Code Review Agent
- Coding Agents and Shadow AI in Your SDLC: What to Measure
Frequently Asked Questions
How do you secure AI-generated code?
Follow ENISA's four steps: identify the security expectations, specify them to the agent, verify the output with review and security scanning in proportion to risk, and record evidence of what changed and who approved it.
Can AI coding assistants write secure code?
Sometimes, but not reliably. In an October 2026 benchmark, the best agent produced code that was both functional and secure on 25.1% of tasks. Plan on independent review and security scanning for every AI-generated change.
Should AI-generated code get a different review process?
It should meet the same security requirements as human code, according to ENISA and the CD Foundation. Scale the depth of review to the sensitivity of the component, the size of the change and how much autonomy the agent had.
What is slopsquatting?
It is an attack in which someone registers a package name that AI models tend to hallucinate, then fills it with malicious code. An internal registry allowlist and lockfiles that fail on unreviewed dependencies block it.
What evidence do auditors expect for AI-assisted changes?
ENISA recommends keeping what changed, why it changed, which checks ran, the results and who approved. It also points toward SBOM updates, signed provenance records and machine-readable attestations in CI/CD.
Written by
Axiom Studio