Across more than 150 language models tested on the same 80 coding tasks, roughly 55 percent of generations produce secure code and 45 percent introduce a known flaw. That ratio has barely moved in two years while syntactic correctness passed 95 percent. Models got better at writing code and no better at writing safe code.
That finding is the one durable number in this field, and almost every article quoting it quotes it wrong. Before the governance question is worth discussing, the evidence needs cleaning up, because three widely repeated figures turn out to describe one research program at different moments and one of them cannot be sourced at all.
Three circulating figures describe one dataset, and one is unsourced
Search for the security of generated code and you will meet “45 percent fail security tests,” “only 55 percent is secure,” and “2.74 times more vulnerabilities than human code.” Readers reasonably conclude the research disagrees with itself. It does not.
| Figure | Source and date | What it measures |
|---|---|---|
| 45 percent introduce a flaw | Veracode, 2025 GenAI Code Security Report, 30 July 2025 | Share of test cases where the model introduced an OWASP Top 10 vulnerability |
| 55 percent produce secure code | Veracode, Spring 2026 GenAI Code Security Update, 24 March 2026 | The same measurement on a later model cohort, stated as a pass rate |
| 2.74 times worse than humans | No primary source located | Not a Veracode finding |
The first two are complements of each other on a continued dataset. Forty-five percent failing and fifty-five percent passing are the same result expressed from opposite ends, measured roughly nine months apart, and the near-identity of the two is itself the finding: the rate held.
That third figure does not appear on Veracode’s own pages. It circulates widely with Veracode attribution and no locatable passage behind it. It is also structurally incompatible with the research design, because the study contains no human-written control group. Eighty tasks were put to models, not to a matched set of developers, so no human-versus-model multiplier can be derived from it. If a vendor deck or a board paper in your organization carries that number, it is worth removing before someone asks where it came from.
AI-generated code security is the measurement of whether a model, given a coding task that can be completed safely or unsafely, chooses the safe implementation. That framing matters for interpreting the numbers, and the next section explains why.
The measurement counts task choices, not lines of code
Veracode’s method was to prompt models to auto-complete a block of code in either a secure or an insecure manner, then analyze the output with static analysis. Veracode’s headline is therefore a per-task rate, not a per-line or per-repository rate.
This distinction gets lost constantly, and it cuts both ways. It means “45 percent of AI code is vulnerable” is a misreading, because the figure is not a share of code volume. It also means the number is harder to dismiss than a volume statistic would be, because each task was constructed so that a safe path existed. No impossible requirement defeated it. It had the option and took the other one, which the research states directly: given a choice between a secure and an insecure method, models chose the insecure option 45 percent of the time.
Its design was 80 coding tasks across four languages, four critical vulnerability classes, and five task instances for each language-and-class combination, run across a model population that has grown past 150. Knowing the sample shape tells you what the number generalizes to: common web vulnerability classes in mainstream languages, assessed one completion at a time. It does not tell you how a model performs across a multi-file refactor, and nobody should extrapolate it there.
Security performance stayed flat while syntax improved sharply
The trend finding is more consequential than the headline rate, and it is the part that should change how an engineering organization plans.
Veracode reports that security pass rates remain approximately 55 percent, virtually identical to where they stood two years earlier, while syntax correctness rates now exceed 95 percent. Its CTO Jens Wessling put the implication plainly: models are getting better at coding accurately but are not improving at security, and larger models do not perform significantly better than smaller ones, which suggests a systemic issue rather than a scaling problem.
Read that last clause carefully, because it invalidates the most common planning assumption in this category. A prevailing bet holds that security problems in generated code are a transitional artifact that the next model generation will absorb. If capability scaling moved the number, waiting would be a rational strategy. The evidence says scaling does not move it, which makes the security gap a standing property of the tooling rather than a temporary one, and that converts review capacity from a stopgap into permanent infrastructure.
There is one qualification worth carrying, and it points at method rather than model size. Veracode found that the GPT-5 series with extended reasoning achieved security pass rates between 70 and 72 percent, a meaningful improvement over the 55 percent baseline. Deliberation at generation time is the lever that moves this, not parameter count. That has a practical reading for teams configuring agents: the settings that let a model reason longer before emitting code earn their latency on anything touching a trust boundary.
Failure concentrates in specific vulnerability classes
The aggregate rate hides a distribution that should drive where review effort goes, because performance by vulnerability class varies enormously.
| Vulnerability class | Security pass rate | Interpretation |
|---|---|---|
| Insecure cryptographic algorithms (CWE-327) | 86 percent | Largely handled |
| SQL injection (CWE-89) | 82 percent | Largely handled |
| Cross-site scripting (CWE-80) | 15 percent | Fails by default |
| Log injection (CWE-117) | 13 percent | Fails by default |
Those figures come from Veracode’s Spring 2026 update, and the spread is the actionable part. Models have effectively learned to parameterize queries and select modern ciphers, because those patterns are ubiquitous, well-documented, and consistently demonstrated in training data. Output encoding and log sanitization are not. Veracode’s earlier 2025 report found the same shape from the other direction, with models failing to defend against cross-site scripting in 86 percent of relevant samples and log injection in 88 percent.
The planning consequence is specific. A review checklist that spends its attention on injection and cryptography is auditing the two things the generator is already good at. Encoding at output boundaries and sanitization before logging are where the generated code is most likely to be wrong, and they are also the two easiest things for a reviewer to skim past, because neither looks like a security decision in the diff.
Java fails most, and the explanation implicates training data age
Java was the riskiest language in the 2025 report at a 72 percent security failure rate, against Python at 38 percent, JavaScript at 43 percent, and C# at 45 percent. The Spring 2026 update continued to find Java worst, reporting a 29 percent security pass rate for it on a later cohort.
Note that these are different measurements rather than a contradiction. A 72 percent failure rate in one report and a 29 percent pass rate in another come from different model populations at different dates, and subtracting one from a hundred to compare them is the kind of arithmetic that produces a wrong number in a slide.
Veracode’s stated hypothesis is that models are over-trained on legacy Java patterns, meaning the millions of lines of older Java in public repositories that predate modern security frameworks and practices. Its October report noted the surprise that many models perform much worse on Java tasks even for vulnerability classes generally easier to avoid, such as SQL injection.
For anyone building on the Salesforce platform, this is the finding to sit with. Apex is a Java-derived language, and the public corpus of Apex is both smaller than Java’s and heavily weighted toward older patterns, including code written before with sharing discipline, before field-level security enforcement was routine, and before bulkification was understood as a correctness requirement rather than a performance tip. The mechanism Veracode proposes for Java applies with more force to Apex, not less. No published study measures Apex specifically, so this is an inference about mechanism rather than a measured result, and it should be stated that way. But it argues for treating generated Apex as higher-risk than the cross-language average rather than lower.
Static analysis catches structure, and cannot reach runtime input
The scanner in your pipeline does real work, and the boundary of that work is documented rather than a matter of opinion.
Salesforce Code Analyzer runs multiple engines over a Salesforce codebase. Its PMD engine performs static analysis on Apex and Visualforce. The Salesforce Graph Engine performs data-flow analysis on Apex, which is what allows rules like ApexFlsViolation to detect create, read, update, delete and field-level security violations across call paths rather than within a single method, and DatabaseOperationsMustUseWithSharing to flag database operations inside classes declared without sharing. A Flow Scanner engine audits Flows. Rules carry tags, so a pipeline can select security rules specifically rather than running everything. A separate AppExchange rule selector prepares managed packages for security review.
Salesforce’s operational guidance for agentic systems recommends integrating that scanner into the deployment pipeline through its CLI or a GitHub action, and then states the limit explicitly: prompt injection and sensitive-data exposure are runtime input threats outside the scope of static code analysis, and detecting them requires specialized agent security testing.
That sentence is the one to quote in your own governance document, because it separates two things organizations routinely merge. A clean scan says the code’s structure does not contain known unsafe patterns. It says nothing about whether the agent built from that code can be talked into misusing its own permissions. Those are different questions answered by different tools, and a program that only buys the first one has a gap it cannot see.
Adversarial testing covers the second question, and it is a distinct gate with its own staffing requirement rather than an extra pass by the build team. Where it sits in a release sequence, and who is allowed to sign it off, belongs to the approval gates that precede activation.
Review is the binding control, and generation volume is what stresses it
If security performance is flat and the generator produces more code per hour than it used to, the constraint moves to review. Salesforce’s own developer guidance for its agentic coding tool states the principle without hedging: generated code requires the same review as human-written code, and the verification list it specifies covers security, bulkification, governor limits, and error handling.
Saying review is mandatory is easy. Making it survive contact with volume is the actual problem, and three things help.
Target review attention using the distribution above rather than spreading it evenly. Encoding at output boundaries, log sanitization, and sharing declarations deserve disproportionate scrutiny on generated diffs. Parameterized queries mostly do not.
Keep changes small enough to review honestly. A reviewer facing a 2,000-line generated change approves it or blocks it; they do not read it. The same batching discipline that makes a regression traceable makes a review real.
Instrument the review stage so you can see it saturating. Review latency is the leading indicator that generation volume has outrun capacity, and it moves well before defect escape rates do. The measured evidence that it moves at all, across a panel of more than 500 engineering organizations, sits in what happens when authoring gets cheap and review does not.
Threat modeling belongs upstream of all of it. Salesforce’s Trust pillar places STRIDE threat modeling before build begins rather than treating it as a review-stage activity, which is the only position from which it changes a design.
What to require before generated code reaches production
Four requirements, stated as gates rather than aspirations.
A scanner in CI/CD with security rules selected, failing the build rather than producing a report somebody reads later. Static analysis that does not block is documentation.
Human review on every generated change, sized so review is feasible, with a checklist weighted toward the classes models fail rather than the classes they pass.
Separate agent security testing for anything with action authority, staffed by people who did not build it, covering injection and escalation rather than code structure.
A record of what was generated, what was reviewed, and by whom. When an incident traces back to a generated change, the question is always who approved it and against what, and reconstructing that after the fact is expensive.
Generated Apex is a reviewable unit of work, not a finished one
The Code Agent inside GetGenerative.ai’s Build Agent generates Apex, Lightning components, and configuration against a client’s actual org metadata rather than against a generic Salesforce. Grounding in the real org is what prevents a class of defect that no scanner catches, where the code is structurally sound and references a field, sharing model, or object relationship that does not exist in that environment.
The surrounding design treats generation as the start of a reviewable unit of work rather than the end of one. The Test Agent produces the regression pass, and the Governance Agent holds the gate that a change has to clear before it moves, which is where a security rule belongs if it is going to be enforced rather than remembered. Architectural Logs record the decision trail, so the approval question has an answer that does not depend on anyone’s recollection.
Generated code inherits the access model it runs inside, and a sharing problem that predates the agent does not announce itself as the agent’s fault. Teams who would rather have review capacity built into delivery than bolted on afterwards can see how the Forward Deployed Engineer model handles it.
Recap
Roughly 55 percent of model-generated code passes security review, a rate flat across two years while syntax correctness exceeded 95 percent, and larger models do not improve it. Failure concentrates in cross-site scripting and log injection rather than SQL injection or cryptography. Java fails most, plausibly from legacy training data. Static analysis cannot reach prompt injection, and review is the binding control.
Frequently Asked Questions
How secure is AI-generated code?
Across more than 150 models on 80 standardized tasks, Veracode found approximately 55 percent of generations produce secure code, meaning 45 percent introduce a known flaw. The figure is a per-task rate rather than a share of code volume, measured on tasks where a safe implementation was available.
Is AI-generated code getting more secure as models improve?
Not on the available evidence. Veracode reports security pass rates stuck near 55 percent across two years while syntax correctness passed 95 percent, and finds larger models no better than smaller ones. Extended reasoning at generation time did move the figure, reaching 70 to 72 percent.
Which vulnerabilities does generated code fail most?
Output-boundary problems. Cross-site scripting shows a 15 percent pass rate and log injection 13 percent, while SQL injection reaches 82 percent and insecure cryptography 86 percent. Review checklists weighted toward injection and cryptography audit the classes models already handle well.
Will a static analysis scanner catch AI-specific risks?
No. Salesforce states that prompt injection and sensitive-data exposure are runtime input threats outside the scope of static code analysis. A scanner validates code structure against known unsafe patterns. Whether an agent can be manipulated into misusing its permissions requires separate agent security testing.
Is generated Apex riskier than generated Python?
No published study measures Apex directly, so treat this as mechanism rather than measurement. Java showed the worst results, which Veracode attributes to over-training on legacy patterns predating modern security frameworks. Apex has a smaller and older public corpus, so the same mechanism applies with more force.
ChatGPT
Claude
Perplexity