
AI code security is the practice of identifying and fixing vulnerabilities in AI-generated code, from insecure patterns copied from training data to business logic flaws that pass functional tests.
AI-generated code isn't inherently less secure than human-written code, but its speed outpaces most teams' ability to review it.
A December 2025 study from Carnegie Mellon, Columbia, and Johns Hopkins found leading models write functionally correct code 61% of the time, and only 10% of that output is both correct and secure.
Here's what the research shows and how to close that gap.
What is AI code security? The 30-second answer
AI code security is the discipline of identifying, testing for, and remediating vulnerabilities specific to AI-generated code.
That covers everything from replicated legacy flaws to business logic errors that need full codebase context to catch.
Bottom line: the code itself isn't the differentiator. The volume and speed at which it ships are why traditional review processes fall behind.
Key risks
Here are the six risk categories:
- Replicated legacy vulnerabilities: Models trained on public code reproduce classic flaws like SQL injection and cross-site scripting at meaningful rates.
- Business logic vulnerabilities: Flaws in application-specific logic that require full codebase visibility to catch, which automated scanners miss.
- Hallucinated insecure patterns: Models occasionally invent plausible-looking but insecure implementations that can spread across a codebase before anyone notices.
- Cryptographic weaknesses: Models handle standard crypto reasonably well, yet still produce flawed implementations at a meaningful rate.
- Hardcoded secrets: API keys and credentials embedded directly in generated code, a common and easily preventable failure mode. Our vibe coding security guide covers this pattern in depth.
- Supply chain exposure: Models can suggest malicious or typo-squatted dependencies pulled from their training data or hallucinated outright.
What the research shows
Vulnerability rates in AI-generated code vary widely across studies, models, and languages, and the range itself is informative.
Early research on GitHub Copilot found roughly 40% of generated programs contained a vulnerability, with C code faring worse than Python.
Later studies using different models found rates closer to 25 to 30%.
A 2024 systematic review of 19 studies concluded there's high agreement that AI models don't produce reliably safe code, even with mitigations in place.
The most recent and strictest study raises the bar further.
Carnegie Mellon, Columbia, and Johns Hopkins researchers found that even though leading models write functionally correct code 61% of the time, only 10% of that code is both correct and secure.
That's a much narrower bar than "contains no known CWE."
A real example shows why this matters at the agent level.
In February 2026, Endor Labs used its AI SAST engine to discover seven undiscovered vulnerabilities in OpenClaw, a popular open-source AI agent, including high-severity request-forgery and auth-bypass flaws.
The OpenClaw team confirmed and patched six of them.
AI code security vs. AI code governance: what's the difference?
The two are used interchangeably, but they answer different questions.
Security finds the problems. Governance makes sure someone's accountable for fixing them.
Our AI code governance tools roundup covers the platforms that combine both.
What I liked and didn't like about the current state of AI code security
Pros (what works)
Automated scanning catches most replicated legacy flaws well. Tools built for this purpose reliably flag SQL injection, XSS, and hardcoded secrets, since these are pattern-matchable issues that security tooling has handled for years.
The tooling response has been fast. Free, developer-first tools now embed directly into AI coding agents via MCP, closing part of the gap between how quickly code ships and how quickly it gets reviewed.
Cons (where it falls short)
Business logic flaws still need a human. Automated tools struggle with vulnerabilities that only make sense in the context of what an application is supposed to do, exactly the category researchers flag as hardest to catch.
The volume problem keeps growing. As more teams adopt AI coding at scale, the gap between code shipped and code properly reviewed widens even as individual tools improve.
Should you worry about AI code security? My take
If any AI-generated code reaches production, even a small share, this deserves dedicated attention, not blind trust that your existing code review process catches AI-specific failure modes.
AI code security needs real investment if you:
- Ship AI-generated code to production regularly.
- Work in a language like C or C++ where AI vulnerability rates run higher.
- Have non-engineers generating code through vibe coding tools.
You can move more gradually if you:
- Use AI only for prototypes and internal experiments with no production path.
- Already run strict human review on every AI-generated change before merge.
How to secure AI-generated code in 6 steps
Rolling this out works as a layered sequence, not a single control:
- Scan for replicated vulnerabilities first. Automated tools reliably catch SQL injection, XSS, and hardcoded secrets, so start there.
- Add human review for business logic. Route anything touching application-specific logic through a reviewer who understands the full codebase.
- Treat AI output as untrusted by default. Review AI-generated code to the same standard as a new contributor's first pull request.
- Check dependencies AI suggests. Verify any new package a model recommends exists and isn't typo-squatted before installing it.
- Test cryptographic implementations specifically. Don't assume a model got encryption or hashing right just because the code runs.
- Monitor in production. Vulnerabilities that pass review sometimes surface only under real traffic patterns, well past the merge point.
Pro tip: Prioritize scanning coverage for C and C++ code specifically, where every major study found higher vulnerability rates than in Python or JavaScript.
AI code security best practices
A few habits separate teams catching real issues from ones drowning in false confidence:
- Don't trust functional tests as a security signal: Code that works and code that's secure are different bars, and the gap between them is where most AI-generated vulnerabilities live.
- Watch for pattern spread: A single hallucinated insecure pattern can get copied across a codebase before anyone notices, so scan broadly, well beyond newly generated files.
- Extend this to low-code and vibe-coded apps: The same risks apply outside traditional IDEs. Our guide to low-code platform security and our secure vibe coding tools roundup cover that surface.
My verdict on AI code security
The honest picture is more nuanced than "AI code is insecure."
Vulnerability rates across real studies range from roughly 10% to 40% depending on how strictly you define secure, which language you're generating, and which model you're using.
That range itself tells you a single number won't serve you well.
What's consistent across all studies is that business logic flaws and volume are the two problems that automated tooling alone doesn't solve.
The Lovable vulnerabilities disclosed in 2025 are a concrete reminder of what happens when a popular AI builder ships without sufficient layered defense.
Where Superblocks fits
Most AI code security tooling scans code inside a traditional development pipeline. It has less visibility into the internal apps and workflows business teams build directly with AI outside that pipeline.
Superblocks is the governed enterprise vibe coding platform, built on a SOC 2 and HIPAA-aligned foundation, where those apps are built inside guardrails from the start.
On Enterprise, Superblocks' security agent scans those apps and redacts secrets within its findings, with role-based access governing who can act on them and audit logs recording every run, finding, and remediation.
Shadow AI is the new shadow IT, and unreviewed AI-generated code is exactly how it gets in the door.
For example, Matthews Real Estate uses Superblocks so business teams can ship internal apps while IT keeps full visibility. Their VP of Product Innovation, Ryan Casey, put it plainly: "We don't have any shadow IT work happening".
To try governed app building for yourself, start with the Superblocks Quickstart Guide.
Or book a demo to see Clark AI generating governed apps in your own environment.
Frequently asked questions
Is AI-generated code secure?
AI-generated code isn't inherently more or less secure than human-written code, but studies find real vulnerability rates from about 10% to 40%, depending on language and model. The bigger risk is speed and volume outpacing review.
What is the biggest risk in AI code security?
The biggest risk in AI code security is business logic vulnerabilities, flaws specific to what an application should do, which need full codebase context to catch and which scanners consistently miss.
What is the difference between AI code security and AI code governance?
AI code security is about finding and fixing vulnerabilities in AI-generated code. AI code governance is about the process: who reviews code, under what policy, with what audit trail.
What tool secures AI-built internal apps and workflows?
Superblocks' security agent scans AI-built internal apps and redacts secrets in its findings, with role-based access controlling who can act on them and audit logs recording every run, covering a surface that IDE-based scanners don't reach.
Do AI coding tools produce more vulnerabilities in some languages than others?
Yes, multiple studies found higher vulnerability rates meaningfully in C and C++ than in Python or JavaScript, largely due to memory management requirements that models struggle to get right consistently.
At Virgin Voyages, non-technical teams now build their own AI apps, with IT governance fully intact. The result: 15+ production apps, seven departments onboard, and zero dedicated frontend engineers.
At Matthews, a marketing manager with zero coding background built an app that auto-generates offering memorandums, cutting turnaround from days to hours. See how the brokerage is putting AI builders on every team, with full governance intact.
Stay tuned for updates
Get the latest Superblocks news and internal tooling market insights.
Request early access
Step 1 of 2
Request early access
Step 2 of 2
You’ve been added to the waitlist!
Book a demo to skip the waitlist
Thank you for your interest!
A member of our team will be in touch soon to schedule a demo.
production apps built
days to build them
semi-technical builders
traditional developers
high-impact solutions shipped
training to get builders productive
SQL experience required
See the full Virgin Voyages customer story, including the apps they built and how their teams use them.

"Those tools are great for proof of concept. But they don't connect well to existing enterprise data sources, and they don't have the governance guardrails that IT requires for production use."
Table of Contents

