Skip to main content

Techtura

Guides · AI

Is AI-generated code secure?

Not by default. AI coding tools write code that runs and tests that pass, but neither proves it’s safe. Here’s where the risks are, and how to check.

How secure is AI-generated code?

It can be secure, but you can’t assume it. In Veracode’s testing of more than 100 models, AI-generated code passed security tests 56% of the time on average (Veracode, 2026). The same code almost always compiled, which is why the gaps are easy to miss.

A model writes the pattern it has seen most often, and the most common pattern isn’t always the safe one. Unless you tell it otherwise, it aims for code that works.

The tests it writes have the same aim. They check that the code runs, not that it holds up against an attacker.

The risks specific to AI-generated code

Familiar flaws, at volume

Missing input checks, injection and weak authentication: the flaws people write too. AI writes them faster than anyone can review them.

Packages that don't exist

Models suggest packages that don’t exist: on average, at least 5.2% from commercial models and 21.7% from open-source ones (Spracklen et al., 2025). Attackers can register those names.

Secrets in code

Public repositories using GitHub Copilot leaked secrets at a 6.4% rate, 40% above the average public repository (GitGuardian, 2025).

Tests that check nothing

AI-written tests often pass without checking anything: placeholders, skipped cases and assertions that can’t fail. Coverage reports still look good.

Less review

At teams with high AI adoption, pull requests merged without any review rose 31% (Faros, vendor study, 2026). More code, and fewer people reading it.

Agents with too much reach

Coding agents can run commands, install packages and change the build pipeline. What they’re allowed to touch is part of your attack surface.

How to make AI-generated code safe to build on

The tools are cheap or free. These decisions are what make them work:

  • Scan every change. Secret scanning, static analysis and dependency scans run on every pull request, and a failure blocks the merge.
  • Check every new package. Install from official registries, pin versions and review each new dependency. The OpenSSF’s guide for AI code assistants recommends the same.
  • Test the tests. Plant deliberate bugs, called mutation testing, and see whether the tests catch them. Coverage tells you a line ran, not that a test would notice it broke.
  • Keep a person on every change. Review AI-written code like a new hire’s, in changes small enough to read.
  • Give the assistant your rules. Instruction files tell AI tools your security standards up front, so fewer problems reach review.
  • Limit what agents can change. No direct pushes to the main branch, required checks they can’t switch off, and no production secrets within reach.

Signs to check your code now

If any of these is true, it’s worth an independent check:

  • Most new code comes from AI tools or agents.
  • A prototype built with AI became the product.
  • Coverage is high, but bugs still reach customers.
  • Pull requests merge without review, or reviews take minutes.
  • Nobody has scanned the repository’s history for secrets.
  • Coding agents can push to the main branch or change the build pipeline.
  • You’re about to launch, raise money or go through due diligence.

Check it with AI Code Assurance

Our AI Code Assurance audit plants deliberate bugs to prove whether your tests catch them, and scans for secrets, static-analysis findings and supply-chain risk. Every finding survives an adversarial second pass and a senior engineer’s review, in 1–2 weeks per system at a fixed fee. Start free: the Code Assurance Scan covers one repository, with a one-page report within 48 hours.

Related services

AI Code Assurance

Find out if your AI-generated code and its tests hold up, before a launch, raise or acquisition.

Learn more about AI Code Assurance →

Agent Harness Engineering

Make your engineers’ coding agents follow your standards, with rules outside the agent’s reach.

Learn more about Agent Harness Engineering →

Verified AI Delivery

New software our engineers build with AI agents, at a fixed price per milestone, with proof on every release.

Learn more about Verified AI Delivery →

Questions about AI-generated code security

Can AI-generated code contain security vulnerabilities?

Yes. It can contain the same flaws people write, such as injection and missing input checks. It also brings its own: packages that don’t exist, secrets pasted into code and tests that check nothing.

How do you secure AI-generated code?

Scan every change for secrets, known flaws and risky dependencies, and block the merge when a scan fails. Test the tests by planting bugs. Keep a person reviewing every change, and limit what coding agents can touch.

Does high test coverage mean the code is safe?

No. Coverage shows that a line ran during a test, not that the test would fail if the line broke. Mutation testing plants deliberate bugs to measure that.

What is slopsquatting?

It’s registering a package name that AI models make up, so code that installs it gets the attacker’s package. Checking that each new dependency is real and expected stops it.

Should we stop using AI coding tools?

No. They’re worth the speed. Put the checks above in your build pipeline, so the code they write is checked the same way every time.

Can AI review AI-generated code?

It helps as a second pair of eyes, not the only one. Our audit challenges every finding with an adversarial second pass, and a senior engineer reviews each one before it reaches you.

Find out if your AI-written code holds up.

A 15-minute conversation, and a straight answer on what to check first. No commitment. No sales pressure. Just answers.