Do AI coding assistants make code less secure?

Early evidence is mixed: in one study developers with an AI assistant wrote insecure code more often and felt surer it was secure; in another, the added security risk was small.

Early signal, tested with LLMs.

Based on two studies from 2023, run in labs or online. One related study is shown but not counted.

Two small controlled studies with mixed results: 47 participants wrote insecure code more often with an AI assistant, while 58 students using Codex made critical security bugs at a rate no greater than 10% more than without it. Treat it as a hypothesis.

How we rate evidence
On this page
  1. Design it like this
  2. What it looks like
  3. How to check it
  4. Trade-offs
  5. What they found
  6. Related studies
  7. Open questions
  8. FAQ
  9. Sources

Design it like this

Our recommendations, based on the studies below.

Flag security-sensitive suggestions and prompt review, especially for overconfident users.

  • Send every AI-written auth, crypto or input-handling change through the same security review as human code.Our recommendation
  • Warn on security-sensitive patterns: crypto, auth, input handling.Our recommendation
  • Highlight lines likely to need edits, to focus review.Our recommendation
  • Don't let the assistant raise confidence without checks.Our recommendation

What it looks like

DoAn assistant that tags generated auth code “security-sensitive: review” and links to guidance.
Don'tSilent insertion of a full encryption routine.

How to check it in your product

Run static analysis on AI-assisted commits vs. others and compare vulnerability rates.

Trade-offs and when it doesn't apply

Unsourced points are our recommendation.

  • Sandoval et al. tested one low-level C task with students.
  • Both studies were small (47 and 58 participants); newer assistants may differ. Our recommendation
  • Security outcomes vary by language and task. Our recommendation
  • More warnings slow development. Our recommendation

What they found

With an AI assistant, developers wrote less secure code and felt surer it was secure

Perry et al. (2023) experiment

Setup
47 participants did five security-related programming tasks in Python, JavaScript and C, with or without an AI code assistant.
Result
With the assistant, they wrote insecure solutions more often on four of the five tasks. They were also more likely to believe their code was secure.
Quote from the paper

“Participants with access to an AI assistant were also more likely to believe they wrote secure code, suggesting that such tools may lead users to be overconfident about security flaws in their code.”

Perry et al., 2023 · Abstract

Students with a Codex assistant made at most slightly more critical security bugs

Sandoval et al. (2023) experiment

Setup
58 computer science undergraduate and graduate students implemented a singly-linked ‘shopping list’ structure in C, with or without a Codex-based code completion assistant (code-cushman-001).
Result
AI-assisted users produced critical security bugs at a rate no greater than 10% more than the control group; the authors judge the security impact small.
Caveat
One low-level C task, with students.
Quote from the paper

“AI-assisted users produce critical security bugs at a rate no greater than 10% more than the control”

Sandoval et al., 2023 · Abstract

Open questions

  • Do newer coding agents still show this pattern?
  • Which warnings reduce overconfidence?
  • Does pairing AI with security linters fix it?

FAQ

Do developers write less secure code with AI?

In Perry et al. (47 participants), those with an AI assistant wrote insecure solutions more often on four of five tasks. In Sandoval et al. (58 students), the added risk was small: critical security bugs at a rate no greater than 10% more than without the assistant.

Are they aware of it?

No. They were more likely to believe their code was secure.

Sources

  1. Do Users Write More Insecure Code with AI Assistants?Neil Perry, Megha Srivastava, Deepak Kumar, Dan Boneh (2023). CCS 2023.Evidence type: experiment · Quote: AbstractAlso cited in: Does relying on AI reduce users' critical thinking?
  2. Lost at C: A User Study on the Security Implications of Large Language Model Code AssistantsGustavo Sandoval, Hammond Pearce, Teo Nys, Ramesh Karri, Siddharth Garg, Brendan Dolan-Gavitt (2023). USENIX Security 2023.Evidence type: experiment · Quote: Abstract
  3. Related study, not countedGeneration Probabilities Are Not Enough: Uncertainty Highlighting in AI Code CompletionsHelena Vasconcelos, Gagan Bansal, Adam Fourney, Q. Vera Liao, Jennifer Wortman Vaughan (2024). ACM TOCHI, 2024 (arXiv 2023).Evidence type: experiment · Quote: Abstract · Evidence produced in 2023Also cited in: Should AI highlight the parts of its output it's unsure about?