Is AI-Generated Code Safe? What the 2026 Data Actually Says
AI writes code that passes your tests and ships to production. The security data tells a very different story. Here is what the studies show, and why the durable fix lives in the place the code runs.
Short answer: AI-generated code is often functionally safe and frequently unsafe in the security sense. The two get confused because the same code passes tests, runs fine, and ships. The gap only shows up later, in a pentest, an incident, or an audit. The measurable data from the last few years is consistent on this point.
Functionally correct is a different bar from secure
The most-cited early benchmark came from NYU researchers in the "Asleep at the Keyboard" study, which evaluated code-completion suggestions across security-relevant scenarios and found roughly 40% of the generated programs contained vulnerabilities mapping to MITRE's most dangerous weakness classes. That was an early model, but the pattern has held: models improved at writing working code faster than they improved at writing safe code.
A more recent Carnegie Mellon benchmark puts the split in sharp relief. SUSVIBES ran an agent over 200 feature-request tasks drawn from real open-source projects and scored the output twice, once for whether it worked and once for whether it was safe. About 61% of solutions were functionally correct, and only 10.5% were secure. The code did the job nine times out of ten and did it safely about one time in ten. Models reproduce the insecure patterns in their training data, and they omit the security controls that were never in the prompt to begin with. That second failure is the harder one, because an absent control gives a scanner nothing to detect.
AI is optimized to produce code that works. "Secure" is a separate target, and current models hit it far less often than they hit "correct." Passing your test suite tells you almost nothing about whether the code is safe on real data.
The volume problem makes review impossible
If this were a handful of snippets, human review would catch it. It is well past that. In a 2026 developer survey reported by Help Net Security, nearly half of organizations already run AI-generated code in production, and more than 80% have had to adjust their development and release processes to cope. Review is buckling under the load: roughly one in ten developers now spend more than 40% of their time reviewing code they didn't write.
The math doesn't close. Generation is effectively free and instant. Careful security review is slow and expensive. As agents move from suggesting lines to autonomously building and running whole tools, the human in the loop becomes a bottleneck everyone is incentivized to skip, which is exactly the moment unreviewed code reaches production data.
Where the vulnerabilities cluster
The failure modes aren't exotic. They map cleanly onto the OWASP Top 10, with broken access control at the top of the list, alongside injection flaws, hardcoded secrets, missing input validation, and business-logic errors. These are well-understood classes. What changed is the rate: AI reintroduces them at machine speed and scale, faster than any review process was designed to absorb.
Why "just scan it" falls short
Static analysis and AI code-review tools help, and you should use them. Nearly half of surveyed teams have already bought code-quality tooling. But scanning catches the vulnerabilities that are present in the code. It misses a missing authorization check, it can't tell you which app touched which customer record, and it has nothing to say about the question an auditor actually asks: what ran against our data, and who approved it?
That is the real shift. The question "is AI-generated code safe?" quietly assumes the safety has to live in the code. At scale it cannot, because nobody is going to manually vet every artifact a fleet of agents produces. The durable answer is to move the guarantee into the boundary the code runs inside: isolate every app, mediate and log every call it makes, and enforce what it is allowed to do regardless of what the model wrote.
Sources
- Pearce et al., "Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributions," NYU / IEEE S&P · arxiv.org/abs/2108.09293
- Zhao et al., "Is Vibe Coding Safe? Benchmarking Vulnerability of Agent-Generated Code in Real-World Tasks" (the SUSVIBES benchmark; 61% functionally correct, 10.5% secure), Carnegie Mellon LTI · arxiv.org/abs/2512.03262
- "AI-generated code risks reach security, legal, and compliance teams" (2026 developer survey), Help Net Security · helpnetsecurity.com
- OWASP Top 10 Web Application Security Risks · owasp.org/www-project-top-ten