Is AI-generated code secure? What the data says

The short answer is uncomfortable: AI-generated code works far more reliably than it is secure, and the gap between those two things is now well measured. This is not a vague worry or a reason to stop using AI to build. It is a specific, repeatable pattern in the data, and once you know its shape you can do something about it.
What the research actually found
Three findings, from independent teams, tell a consistent story. In a controlled Stanford experiment presented at ACM CCS 2023, developers given an AI assistant wrote less secure code than those without one, and, crucially, felt more confident that their code was secure. At scale, NYU researchers found that roughly 40% of the programs GitHub Copilot generated in security-relevant scenarios contained a vulnerability from MITRE's Top 25. And Veracode's 2025 GenAI Code Security Report tested over 100 models and found 45% of generated samples introduced an OWASP Top 10 weakness, with newer and larger models no safer than older ones.
Put together: a controlled study, a scale study, and a cross-model study all land in the same range, and the newest models did not fix it. That last point matters most. If this were a capability gap, better models would close it. They have not, which says the problem is structural to how these systems generate code, not a temporary rough edge.
Why it happens
A model trained to produce plausible, working code optimizes for exactly that: code that looks right and runs. Security lives in the things that do not show up when the happy path runs, the authorization check, the input nobody pastes in a demo, the assumption that the caller is who they claim. None of that is visible in a passing test, so none of it is reliably generated. The model is not careless; it is doing precisely what it was optimized to do, and security was never the objective function.
The part that makes it worse
The Stanford overconfidence result is the quiet danger. If AI-assisted code felt risky, teams would scrutinize it harder. Instead it feels finished, so it ships with less review, not more. Speed goes up, adversarial attention goes down, and the result is more instances of well-understood vulnerability classes than human review was ever built to catch. AI did not invent new bugs. It mass-produced the old ones and made everyone feel safer doing it. We go deeper on the specific failure patterns in what AI-generated code gets wrong about security.
What to do about it
The fix is not to write less AI code. It is to test it like an adversary at the same speed you generate it, so the testing keeps pace instead of falling a release behind. Because the mistakes are predictable, they are findable, and findable at scale. That is what Uvy does: it tests AI-built applications for the specific, repeating weaknesses they tend to ship, and proves the exploitable ones with a working exploit. See how it works.