Evaluating and Preventing Security Smells in AI-Generated Ansible Code
cs.SE, cs.AI, cs.CR
Submitted: 2026-08-25
Updated: 2026-08-25
Comments: 14 pages, 2 figures, 3 tables. Dataset and prompts available at https://figshare.com/s/67c36294c704c7ab5ae5
Code: https://github.com/stackblitz-labs/bolt.diy
Project page: https://livecodebench.github.io
License: http://creativecommons.org/licenses/by/4.0/
The gist: AI coding assistants generate Infrastructure as Code, yet no work has examined whether this code meets security requirements.
Terminology
Abstract
AI coding assistants generate Infrastructure as Code, yet no work has examined whether this code meets security requirements. This matters because security smells in infrastructure code propagate to deployed systems, producing infrastructure that is insecure and untrustworthy. We evaluate 16 AI models generating Ansible roles for Apache Tomcat v10 and MongoDB v7, analysing 278 Ansible roles against CIS benchmarks. Without security guidance, all 16 AI models produced code containing security smells, resulting in vulnerable infrastructure that fails compliance verification and underperforms code written by human developers. We introduce an approach integrating Ansible best practices and CIS benchmarks into prompts through an extended CO-STAR framework, enabling security smell prevention during synthesis rather than detection after deployment. When this approach is applied, 4 out of 16 models generate compliant code, with the leading model achieving 95%-100% CIS compliance, a fourfold improvement over humans at 23%-43%, with overall code quality improving by 19%-49%. The remaining 12 models fail not because they cannot generate code but because they cannot follow instructions with multiple constraints. For capable models, the approach requires no retraining and can be adopted through system prompts.
Sources
- Can We Trust AI Benchmarks? An Interdisciplinary Review of Current Issues in AI Evaluation
- CodeLMSec Benchmark: Systematically Evaluating and Finding Security Vulnerabilities in Black-Box Code Language Models
- A Framework for Measuring the Quality of Infrastructure-as-Code Scripts
Related papers
- Falsification-Based Verification of LLM-Generated Optimization Models: Sound Test Batteries and Their Detection Limits
- GitSkills: A Dataset of Agent Skills on GitHub
- For Coding Agents, the Repository Matters
- SABER: Benchmarking Operational Safety of LLM Coding Agents in Stateful Project Workspaces
- PackMonitor: Enabling Zero Package Hallucinations Through Decoding-Time Monitoring
- IntentCoding: Amplifying User Intent in Code Generation