caelo

Caelo › Guides › Can AI write secure code?

Can AI write secure code? What peer-reviewed studies found

By Arthi Arumugam, Irth Labs · Published · Updated

Short answerSometimes, but not reliably. In a peer-reviewed benchmark of 186 real-world tasks, the top agent wrote working code for 57% of tasks but working and secure code for only 11.8%. Asking for security helps a little and does not close the gap, so AI-written code still needs a security check before real users touch it.

What do the benchmarks show?

  • In a peer-reviewed benchmark of AI-generated backends, security exploits worked on around half of the programs that were functionally correct. (BaxBench, ICML 2025.)
  • In a peer-reviewed benchmark of 186 real-world coding tasks, the agent that solved the most tasks produced working code for 57% of them, but code that was both working and secure for only 11.8%. (SusVibes, ICML 2026.)
  • In the same SusVibes benchmark, adding security hints to the request raised the share of tasks that were both correct and secure only slightly (from 11.8% to at most 15.1%) and lowered the share of working solutions (from 57% to between 50% and 55.4%).

Why does AI miss security?

Security is mostly about things that should not happen: a stranger reading your customers' orders, a user making themselves an admin, an order marked paid without payment. You rarely describe those in a prompt, and code that skips them still looks and works fine in a demo.

Letting the AI fix its own output is not a full answer either. A peer-reviewed 2025 study of one model (GPT-4o) reported that letting AI repeatedly 'improve' code without a human increased critical vulnerabilities by 37.6% after five rounds.

How do you get safer code from AI tools?

  1. State the security rules in plain words: who may read, create, change and delete each kind of data.
  2. Keep secrets out of the browser. Ask for server-side handling of anything that uses a secret key.
  3. Make payments final only through a verified webhook from your payment provider.
  4. After every big change, re-check access rules yourself, or with a scanner, rather than trusting the AI's summary.
  5. Before launch, have someone who did not write the code check it. Our App Health Check does that in 48 hours.

1. Run the free local check

npx caelo .

Caelo is a free, open source (MIT) command line tool and MCP server from Irth Labs that checks the files of an AI-built app for exposed API keys, Supabase and Firebase misconfigurations and .env files with real values. It runs on your machine, uploads nothing and uses no AI model. Each finding comes with a plain-English fix.

2. Act on a finding

Follow the fix in your report and run Caelo again. If Git could commit an untracked file containing secrets, preview a US$19 quick fix for that file.

For findings that need an engineer, Irth Labs offers a US$490 App Health Check. You receive a written report within 48 hours and a fixed repair quote. The fee counts toward the repair if you proceed.

Book the App Health Check See repair services

Questions

Is Copilot or Cursor code secure?

It can be, but you cannot assume it. Studies find that working code is often not secure code. Review access control, secrets and input handling yourself.

Do better AI models write more secure code?

Not reliably. In the SusVibes benchmark the model that solved the most tasks was not the one with the most secure results, and none of the studies we cite found a model that removes the need for a security check.

Does adding 'make it secure' to my prompt work?

It helps a little at best. One peer-reviewed benchmark found security hints raised the share of correct and secure tasks from 11.8% to at most 15.1%, while fewer solutions worked at all. Specific rules work better than general instructions.

Sources