Skip to main content
Published in Engineering Insights

AI-Generated Code Security Risks: What Buyers Should Check

AI-Generated Code Security Risks: What Buyers Should Check
Table of contents
  1. Is AI-Generated Code Secure?
  2. What Do the Studies Actually Show?
  3. What Are the Main Risks in AI-Generated Code?
    1. Known flaw patterns
    2. Invented packages
    3. False confidence
    4. Tests the AI wrote for itself
    5. Agents with live access
  4. Is AI-Written Code Worse Than Code People Write?
  5. What Should a Vendor's Review Process Include?
  6. What Should You Ask a Software Vendor That Uses AI?
  7. What Should the Contract Say About Security?
  8. What About AI Agents With Access to Your Systems?
  9. How Gnar Checks AI-Written Code
  10. What If Your App Was Already Built With AI Tools?

AI-generated code security risks are real, and AI-written code is not secure by default. In lab tests, AI tools often write code with known flaws: Veracode found that 45% of code samples failed security tests across more than 100 models. Whether your software ends up secure depends on the review and testing around the AI, and on what its AI agents can reach. Those are what a buyer should check.

This post is for a CIO, COO or owner who is buying custom software from a firm that writes code with AI tools such as Cursor, Claude Code or Copilot. It gives you the study numbers side by side, questions to send a vendor, and contract terms to add. If your app already has users, our hardening service for AI prototypes is the place to start.

The Gnar Company's guide for technical leaders says AI-generated code must pass clear acceptance criteria, and it says "No code ships without human eyes on it."

Is AI-Generated Code Secure?#

AI-generated code is not secure by default, and it is not automatically unsafe either; its security depends on the people and tests around the tool.

Veracode found that 45% of code samples failed security tests and introduced OWASP Top 10 security vulnerabilities. The OWASP Top 10 is a public list of the most critical security risks to web applications. Veracode also found that "while the models got better at writing functional or syntactically correct code, they were no better at writing secure code." A classic flaw is SQL injection. The code builds a database query by gluing in text a user typed, with no input validation, so a crafted entry can read or change data. The picture at the top of this post shows one.

A 2025 study of public GitHub repositories found that 87.9% of AI-generated code did not contain identifiable CWE-mapped vulnerabilities. CWE stands for Common Weakness Enumeration, a list of known software weakness types. The study reports only the weaknesses its scanner identified. One number comes from a lab test. The other comes from files people published, run through a scanner.

A vendor's tool list says little about whether your software will be safe. Its review process says more, and you can ask to see the proof.

What Do the Studies Actually Show?#

The numbers range from about 40% vulnerable to 87.9% with no identifiable flaw found by a scanner, because the studies test different things. Some ask a model to write code and then scan it. Some watch people work with an assistant. One scans code that people already published.

Two of the studies, NYU in 2021 and Stanford, used older tools. An agent is an AI tool that takes actions on its own, such as running commands or changing files. None of the studies tests today's agent tools, such as Claude Code or Cursor in agent mode. They show patterns worth watching in the tools your vendor uses this year. They do not measure those tools directly.

  • NYU, Pearce et al. (2021). Tested: 1,689 programs from GitHub Copilot. Found: about 40% were vulnerable. Keep in mind: an early Copilot version.
  • Stanford, Perry et al. (2023). Tested: 47 people coding with and without an AI assistant. Found: the assistant group wrote less secure code and felt more sure of it. Keep in mind: a small group and an older assistant.
  • Spracklen et al. (2025). Tested: package names that code models suggest. Found: at least 5.2% were invented for commercial models and 21.7% for open-source models. Keep in mind: attackers can register invented names as malicious packages.
  • Veracode (2025). Tested: code samples from more than 100 models. Found: 45% failed security tests, and Java had a 72% failure rate. Keep in mind: these are lab samples.
  • Schreiber and Tippe (2025). Tested: AI-generated code in public GitHub repositories. Found: 87.9% had no identifiable CWE-mapped vulnerabilities. Keep in mind: mostly ChatGPT files, and a scan finds only what it has a rule for.
  • Google DORA (2024). Tested: delivery teams and their AI use. Found: delivery stability fell an estimated 7.2% for every 25% increase in AI adoption. Keep in mind: it measures release stability.
  • Georgetown CSET (2024). Tested: a policy review of the research. Found: models "frequently output insecure code". Keep in mind: it names three risk groups.

The percentages are not competing estimates of one risk. The vulnerability studies each count a different thing: programs, people, package names, samples or published files. DORA measures delivery stability, and Georgetown's paper is a policy review.

What Are the Main Risks in AI-Generated Code?#

AI-generated code introduces five risks a buyer can check: known flaw patterns, invented packages, false confidence, tests the AI wrote for itself, and agents with live access.

Georgetown's research center groups the risk into three parts: models generating insecure code, models vulnerable to attack and manipulation, and downstream impacts such as feedback loops. The five risks below are the ones a buyer can check.

Known flaw patterns#

Both the NYU and Veracode results show the tools write code with known flaws. The Canadian Centre for Cyber Security explains why: the training data behind these models can include vulnerabilities, outdated practices and intentionally malicious code, and similar patterns can show up in what they write. When AI generates code, have a reviewer check it for insecure patterns and for errors in business logic, such as which customer may see which record. A scanner and a reviewer can catch many of them, if the vendor runs both.

Invented packages#

A package, also called a dependency, is outside code your app pulls in, usually from third party libraries. AI assistants sometimes suggest package names that do not exist. The Spracklen team measured at least 5.2% invented packages for commercial models and 21.7% for open-source models. The OWASP Secure Coding with AI Cheat Sheet says coding assistants frequently suggest package names that do not exist. The cheat sheet warns that attackers watch for these invented names and register malicious packages with matching names. So a person has to confirm that each new package comes from the intended source and is the one the project meant to use.

False confidence#

In the Stanford study, people with an AI assistant wrote less secure code and were more likely to believe it was secure. Ask who approves each change, and check that the approver is not the person who prompted the tool.

Tests the AI wrote for itself#

OWASP's cheat sheet says a passing test suite written by the same agent that wrote the code gives no independent assurance. If the same tool writes both the code and the tests, the tests can share the code's blind spots. Ask who wrote the tests for logins and payments.

Agents with live access#

An agent with access to live systems can do harm even when the code it writes is fine. Ask the vendor what each of its agents can reach.

Is AI-Written Code Worse Than Code People Write?#

The studies do not settle it, and a buyer does not need them to; treat AI code the way you would treat code from a stranger.

The Stanford study came closest to a direct comparison. People with an assistant wrote less secure code than people without one, and they felt more sure of it. That study used an older tool and 47 participants, so treat it as a warning.

OWASP's guidance on improper output handling gives the practical rule: "Treat the model as any other user, adopting a zero-trust approach". Zero trust means nothing is accepted because of where it came from. Everything is checked.

The Canadian Centre for Cyber Security says the same in its guidance on vibe coding, which is building software by describing it to an AI tool. A single model reviewing its own code is a weak control on its own. A qualified programmer or reviewer should verify, correct and approve AI-generated code before it is deployed.

Ask about AI code what you would ask about any outside developer's work: who read it, who approved it and what tests ran. The answers should not change because an AI wrote the first draft.

What Should a Vendor's Review Process Include?#

A good review process has a named person who did not write the change approving it, automated scans on every change, a check that every outside package is real, tests a qualified person wrote or approved for logins and payments, and agents kept away from live systems.

  • A second person approves every change. A pull request is a proposed code change someone reviews. The final approver should be a named person who did not prompt the AI tool or write the change.
  • Scans run on every change. Static analysis, also called static application security testing (SAST), reads the source code for known flaw patterns. Secrets detection catches keys left in code, and dependency scanning flags outside packages with known problems. Those three run on every change. Dynamic testing (DAST) probes the running app, and it runs before each deployment. The Canadian Centre for Cyber Security recommends SAST and DAST to check code before deployment. Scans sit beside human review and do not replace it.
  • Every outside package is checked. A person verifies each new package's source, confirms it is the intended dependency, and approves it for the project before anyone installs it.
  • A qualified person writes or approves the tests that guard logins, payments and permissions. That includes what each test expects to happen. These are the places where one mistake exposes customer data.
  • Agents stay away from live systems. An AI agent should work in a test copy of your software and data. It should never have credentials that let it reach production systems or live data.

Our post on what a codebase audit should include covers an outside read of code you already have.

What Should You Ask a Software Vendor That Uses AI?#

Ask nine questions and ask for proof with each answer, because a vendor with a real process can show its work.

The table gives each question, what a good answer sounds like, and the proof to request. Send it to the vendor before you sign.

Question What a good answer sounds like Proof to ask for
Which AI tools touch our code, and for what jobs? A short, specific list of tools and tasks. The list written into the statement of work.
Who reviews AI-written changes before they merge? A named person who did not prompt or write the change signs off at the pull request stage. A sample pull request showing who prompted or wrote the change, who reviewed it and who approved it.
What automated scans run on every change? Code scans, secrets detection and package checks on each change, and dynamic testing before each deployment. A recent scan report tied to a sample change, showing the decision on each finding (or that none are open), plus the settings that run checks on every change.
How do you confirm outside packages are real? A person verifies each new package's source, confirms it is the intended one, and approves it for the project. The list of packages and versions, plus a sample change that added one.
Who writes the tests for logins, payments and permissions? A qualified person writes or approves them, including what each test expects. The AI that wrote the code is never the only check. The tests for those parts, with the review that approved them.
What can your AI agents reach? A test copy only. No production data and no live keys. A written list of what each agent can read, change and delete, plus the access settings that enforce it.
Does any of our code or data train an AI model? A direct answer for each tool, matched to its settings and data terms. Each tool's data terms, and the answer written into the contract.
What happens when a security bug shows up after launch? A named party that fixes it, who pays, a response time and a fix time, and a coverage period with a start date. The warranty or support text itself.
Show us a flaw your scans or reviewers caught in AI-written code. A real catch, how it was fixed, and what changed afterward. A redacted pull request or scan finding.

When the proof arrives, check three things. The pull request should name who prompted or wrote the change, and a different person should have approved it. The scan report should show a decision on each finding. The tests for logins and payments should show who reviewed them.

What Should the Contract Say About Security?#

The contract should define a security bug, then say who fixes one found after launch, how fast, for how long, whether your code can train any model, and which AI tools and agents may touch your code and data. This is general information. It is not legal advice. Have your own lawyer read the final terms.

  • What counts as a security bug. Write down the security requirements the software must meet, using plain examples: one customer must never see another customer's data, every page that needs a login checks it, and no secret keys sit in the code. A failure of any of these written security requirements is a security bug. Also agree whether open scan findings block acceptance.
  • Who fixes it. Name the party that fixes a security bug found after launch, and say who pays. Our post on what a software warranty should cover lists the points to check.
  • How fast. Agree on a response time and a fix time, each in days or hours. Responding to a report and fixing the problem are different promises. A promise to respond "promptly" cannot be tested.
  • How long. State the length of the coverage period and when it starts.
  • AI tools. List the AI coding tools and AI models allowed to touch your code, and require notice before a new one is added.
  • Training. For each AI tool, write down whether your code and data can be used to train a model, matched to that tool's data terms. If you want a flat no, put it in the contract.
  • Agent access. Limit AI agents to test systems and test data. Prohibit access to production systems, production data and live keys. Name who approves any change within those limits.
  • Review records. Give yourself the right to see how AI-generated code was reviewed, what scans ran and who approved each change.
  • A shared vocabulary. NIST's Secure Software Development Framework, SP 800-218, says that because it offers a common vocabulary for secure software development, software buyers can use it to improve communication with suppliers. Ask the vendor which of its practices map to it.
  • Ownership of outcomes. CISA's Secure by Design principles ask software makers to take ownership of customer security outcomes. CISA's guidance gives you language for asking the same of a vendor.

You do not need to read the whole NIST framework. Its value is that you and your vendor can point to the same document.

What About AI Agents With Access to Your Systems?#

Code quality and live access are separate risks, and an agent that can reach your production systems can do damage that no code review would have prevented.

Fortune reported in July 2025 that an AI coding agent from Replit reportedly deleted a live database during a code freeze, and that the incident prompted a response from the company's CEO. This is one reported incident, and the details come from that reporting.

An agent with the ability to act on a live system can change it, and a scan of the code cannot lower that risk. Ask the vendor whether its agents can reach your live data, and what stops them from changing or deleting anything. A good answer keeps the places where agents work apart from the places where your customers work. Agents use a test copy. Only a person, following a reviewed process, moves changes into production.

How Gnar Checks AI-Written Code#

The Gnar Company uses people to check every AI-written change, and its published rules say that human eyes, clear acceptance criteria and an independent approver come first.

Gnar's guide for technical leaders says that AI-generated code must pass clear acceptance criteria and that "No code ships without human eyes on it." The same guide says Gnar uses Cursor as its primary tool, with GitHub Copilot for code reviews.

Gnar's code review post sets the approval rule: "The person who gives final approval cannot be the code's author." The Canadian Centre for Cyber Security says a qualified person should approve AI-generated code before deployment. Gnar's rule adds that the final approver is never the code's author.

After launch, Gnar's home page says: "For 12 months after launch, we fix any code that doesn't work the way we agreed, at no charge." The full guarantee is "Three commitments on every build engagement: a fixed milestone price with any overage on us, a guaranteed outcome meaning the software works as specified or we fix it, and a twelve-month bug-free warranty." It covers Discovery, Build, Forge and Maintain. It does not cover Embed. These are Gnar's names for its engagement types, so ask which one your project is. That warranty is tied to what was agreed, so write your security requirements into the agreement, and ask about response times for security bugs in writing.

The numbers in this post come from the public studies. Gnar's pages describe how Gnar works.

What If Your App Was Already Built With AI Tools?#

If an AI tool built your app and it has users, have someone check it for security issues and vulnerable code before you add more customers.

Our post on what to do when your vibe-coded app has users walks through the first steps.

Gnar's hardening page states what the work targets: "We look for security holes and close the ones we find: one customer seeing another customer's data, secret keys left in the code, or pages that skip the login." A free code audit is offered under an NDA, which is a privacy agreement. Gnar's page says the audit tells you whether to fix the app, rebuild it, or leave it as it is.

If you want a second set of eyes on code that AI tools wrote, contact Gnar about a free code audit.

Frequently asked questions

Can AI write secure code?

Sometimes, but not reliably. Veracode found 45% of code samples from 100+ models failed security tests, while a study of public repositories found no identifiable CWE-mapped vulnerability in 87.9% of AI-generated code. CWE stands for Common Weakness Enumeration, a list of known software weakness types, and the study counts only the weaknesses its scanner identified. Both can be true because the studies test different things. Secure results depend on review, scans and tests around the tool.

Is code from Copilot or Cursor safe to ship?

Not without review. OWASP says to treat the model as any other user and adopt a zero-trust approach to what it produces. That means checking AI output the way you would check code from a stranger, with a second person, automated scans and tests, before it reaches customers.

Should a software vendor tell us they use AI?

Yes, and you should ask. As general advice, have the vendor list each AI tool it uses on your code in the statement of work. CISA's Secure by Design guidance names radical transparency and accountability as a principle, and a written tool list is a simple way to see it in practice.

Who is responsible for a bug in AI-written code?

The OWASP Secure Coding with AI Cheat Sheet says AI tools do not accept responsibility for the code they generate. Put a named owner for post-launch security fixes in your contract, and ask who approved the change that shipped.

How do we check a vendor's claims about AI code security?

Ask for proof instead of promises. Request a sample pull request with its reviewer and approval, a recent security scan report that shows static analysis results, the vendor's list of AI tools, and the warranty text. Redacted samples are fine, as long as they show who approved each change and the decision on each scan finding.

Does The Gnar Company check AI-written code?

Yes. The Gnar Company's guide for technical leaders says "No code ships without human eyes on it," and its code review post says "The person who gives final approval cannot be the code's author." For 12 months after launch, Gnar fixes any code that doesn't work the way it was agreed, at no charge. That covers Discovery, Build, Forge and Maintain, which are Gnar's names for its engagement types. It does not cover Embed.

Where to go from here

  • Your US company does over $10M a year in revenue, and its order system is holding you back.

    Talk to Pete Whiting
  • You want AI to save your company money. With Compass, if we don't find at least $350,000 a year in savings, you don't pay.

    See how Compass works
  • Comparing firms? Here are the questions to ask any of them.

    See the questions
  • Pricing a build? Here is what it costs and how the price holds.

    See the price guide
  • Everyone else: get our newest posts by email.

    Get the newsletter

Stay In The Loop

Never miss an update. Get the latest blogs, webinars, and expert insights straight to your inbox from The Gnar.