AI
LLMs fail to reliably produce secure code, even when functionally correct
A new benchmark reveals that code generated by large language models and AI agents passes functional tests far more often than security checks—exposing a critical gap in automated software development.
Researchers have introduced DualGauge, an automated testing framework that simultaneously checks whether code generated from natural-language instructions is both functionally correct and secure. The findings are sobering: even the best-performing language models achieve joint security-and-functionality success rates below 15% across Python, C++, and JavaScript.
The problem: Security masked by functional correctness#
Most existing benchmarks evaluate code generation by asking whether the output works as specified—but working code is not the same as safe code. A program can perform its intended task perfectly while containing exploitable security vulnerabilities or logic flaws. DualGauge addresses this blind spot by pairing functional tests with security tests derived from the same specification, creating a unified benchmark that surfaces mismatches between what code does and what code should do.
The study examined 307 coding tasks across three popular languages and tested 10 representative LLMs. Results showed that functional tests alone substantially overestimate the quality of generated code. A model might pass 60% of functional tests but only 10% of joint security-functionality evaluations—meaning correctness alone is an unreliable proxy for trustworthiness.
Why stronger models don't automatically generate safer code#
The researchers evaluated several factors that industry commonly associates with better code generation:
- Model scale (larger models)
- Extended reasoning capabilities
- Quantization (model compression)
- Instruction tuning
- Code-specialized fine-tuning
None of these consistently improved joint performance. This finding contradicts the assumption that simply building bigger or more capable models automatically yields safer, more secure code. The implication is that secure-and-correct code generation requires targeted solutions, not just scaling existing approaches.
Coding agents struggle without reliable guidance#
Three leading AI coding agents—Codex, OpenHands, and Claude Code—were also evaluated. These tools work iteratively, attempting to refine code through multiple generation-and-test cycles. However, on specification-only tasks, iterative scaffolding proved unreliable. Performance varied dramatically depending on how the agent was prompted or structured, and two of the three agents failed to outperform a simple direct model call.

