Skip to main content
USA-Based Digital Agency

AI security guide · Updated

AI coding assistant security: what the research shows

AI coding assistants write working code fast, but studies keep finding that a large share of it is insecure, that models invent package names attackers can register, and that AI-assisted commits leak secrets more often. None of this means you should stop using them. It means AI-written code needs the same review, scanning and permission limits as any other code, applied every time.

By George Shvaya, founder of Webvello · Published

Key takeaways

  • Veracode’s 2025 tests found AI-generated code introduced security vulnerabilities in 45% of cases across 80 coding tasks and more than 100 models.
  • A USENIX Security 2025 study found models recommended non-existent packages at rates of at least 5.2% for commercial models and 21.7% for open-source models, producing 205,474 unique hallucinated names.
  • GitGuardian reported a 3.2% secret-leak rate for Claude Code-assisted public commits in 2025, against a 1.5% baseline across all public GitHub commits.
  • In a CCS 2023 study, developers with an AI assistant wrote significantly less secure code and were more likely to believe it was secure.
  • Coding agents from Anthropic, OpenAI and GitHub restrict network and command access by default; keep those limits on.

How secure is AI-generated code?

Across years and models, studies find a large share of generated code fails security tests.
Studies measuring the security of AI-generated code (checked November 16, 2026)
StudyWhat was testedFinding
Veracode, July 202580 curated coding tasks across more than 100 large language modelsVulnerabilities introduced in 45% of cases; Java failed more than 70% of the time
BaxBench, Feb 2025 (preprint)392 backend tasksThe best model was correct 62% of the time, and exploits succeeded on around half of the correct programs from each model
Perry et al., CCS 2023Developers with and without an AI assistantThose with the assistant wrote significantly less secure code and were more likely to think it was secure
Pearce et al., IEEE S&P 20221,689 programs from 89 scenarios targeting high-risk weaknessesApproximately 40% were vulnerable

The Veracode figure is a share of test cases, not of all AI-written code everywhere, and the Pearce scenarios were chosen to target risky weaknesses. Both still point the same way: generated code that runs is not the same as generated code that is safe. In Veracode’s tests, cross-site scripting and log injection failed in 86% and 88% of cases.

What are hallucinated packages and slopsquatting?

Models sometimes recommend packages that do not exist. Anyone can register that name and publish malware under it.

Spracklen and colleagues tested 16 popular models on 576,000 code samples in Python and JavaScript. They found hallucinated package rates of “at least 5.2% for commercial models and 21.7% for open-source models,” with “205,474 unique examples of hallucinated package names” (USENIX Security 2025).

Registering one of those names is called slopsquatting, a term that, according to Andrew Nesbitt, came out of an April 2025 conversation between him and Seth Larson of the Python Software Foundation (Nesbitt). The defense is simple and often skipped: check that every new dependency exists, is the package you meant, and has a real maintainer and history before installing it.

Do AI coding tools leak more secrets?

One large 2026 analysis found AI-assisted public commits leaked secrets at about twice the baseline rate.

GitGuardian counted 28.65 million new hardcoded secrets added to public GitHub commits in 2025, up 34% year over year, and reported that “Claude Code-assisted commits showed a 3.2% secret-leak rate, versus a 1.5% baseline across all public GitHub commits” (GitGuardian 2026). The report does not detail how AI-assisted commits were identified, so treat the comparison as a signal, not a precise rate. Either way, secret scanning belongs in every repository an assistant can write to.

Shipping code written with AI?

Tell us about your stack and tools. We will tell you which checks you are missing.

What permissions should an AI coding agent have?

As few as the task needs. The vendors ship restrictive defaults for a reason.
Default protections described in coding agent documentation (accessed November 16, 2026)
AgentWhat the documentation says
Claude CodeIn manual mode it “starts with read-only permissions” and asks before editing files, running tests or executing commands. Its sandbox restricts file access to specific directories and gives sandboxed commands “no direct route to the network” (sandboxing docs).
OpenAI Codex“By default, the agent runs with network access turned off.” The docs warn that prompt injection can make the agent fetch and follow untrusted instructions.
GitHub Copilot cloud agentGitHub filters hidden characters from user input and restricts the agent’s access to the internet.

Claude Code’s docs also note that “no system is completely immune to all attacks” (sandboxing). Agents read issues, pull requests and docs, all places prompt injection can hide. For rolling agents out across a team, see Claude Code consulting and our article on AI coding agent security for enterprises.

How should teams review AI-written code?

The same way as any code, with a few checks aimed at what assistants get wrong most.
  • Every AI-written change goes through a pull request and a human review, never straight to main.
  • Static analysis and dependency scanning run in CI on every change, whoever wrote it.
  • New dependencies are checked by hand: does the package exist, is it the one intended, and who maintains it?
  • Secret scanning runs on every push and in pre-commit hooks, and found secrets are rotated, not just deleted.
  • Input validation, output encoding and authorization checks get explicit review; these are where generated code fails most.
  • Agents run with read-only or sandboxed defaults, and broader permissions are granted per task.

Deciding which dependency alerts to act on is its own skill; see dependency vulnerability triage.

Pages that go deeper on the pieces this one touches.

Common questions

Straight answers to what owners ask us first.

Should we stop using AI coding assistants?

No. The research shows AI-written code needs review, not that it should be avoided. Teams that pair assistants with code review, CI scanning, dependency checks and restricted agent permissions get the speed without skipping the safeguards.

Is AI-generated code less secure than human code?

Studies differ in design, so a single comparison number would mislead. What they agree on is that generated code often contains common weaknesses and that developers using assistants can become overconfident, which is why review matters more, not less.

What is slopsquatting?

Registering a package name that AI models tend to hallucinate, so that developers who install the suggested package get the attacker’s code instead.

Can you audit code our team wrote with AI tools?

Yes. Our AI code security audit reviews the code, its dependencies and its secrets handling, and checks how your coding agents are configured.

Keep the speed, add the checks

We audit AI-written code and dependencies and set up the reviews and scans that catch what assistants miss.