Evaluating and Preventing Security Smells in AI-Generated Ansible Code
Organizations: School of Computing and Mathematical Sciences, University of Waikato, Hamilton, New Zealand 3240
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.
Figures & tables
| Organisation | Model Name | Parameters | Context Window | License | SWE Bench | LiveCodeBench | Benchmark Note |
| Alibaba | Qwen3-235B-A22B | 235B | 128K | ✕ | 70.70% | LiveCodeBench v5 | |
| Amazon | Nova Pro | ✕ | 300K | 42.4% | ✕ | SWE-bench Verified | |
| Anthropic | Claude Sonnet 4 | ✕ | 200K | 80.20% | ✕ | SWE-bench high | |
| Anthropic | Claude Opus 4 | ✕ | 200K | 79.40% | ✕ | SWE-bench high | |
| Anthropic | Claude Sonnet 3.7 | ✕ | 200K | 70.30% | ✕ | SWE-bench high compute | |
| DeepSeek | DeepSeek V3 | 671B | 128K | 42.00% | 37.60% | SWE-bench Verified, LiveCodeBench chat model |
| Category | Model Name | Q3 Answer | Security Score (SS) | Total Quality Score (QS) | Category Avg (SS, QS) |
| Appropriate Standards | Claude Opus 4 | Ansible Best Practices | 85 (0.6136) | 21 (5.07) | 0.599, 4.08 |
| GPT 4o | ISO/IEC 25010 & 29110, OWASP IaC Sec Guide | 114 (0.6068) | 115 (4.06) | ||
| DeepSeek V3 | ISO/IEC 25010, ISO/IEC 27001 (Indirect) | 122 (0.5944) | 117 (4.030) | ||
| Grok 4 | General ISO/IEC 25010 Guidelines | 116 (0.6049) | 118 (4.01) | ||
| Pixtral Large | Ansible Best Practices | 124 (0.5494) | 128 (3.85) | ||
| Claude Sonnet 3.7 | General Software & Ansible Best Practices | 84 (0.6142) | 129 (3.80) |
| Model | Context Window | Structure/Security Score | CIS-CAT Compliance | Rank (Total Quality Score) | |||
| Tomcat | MongoDB | Tomcat | MongoDB | Tomcat | MongoDB | ||
| Claude Opus 4 | 200K | 1.0/0.94 | 1.0/1.0 | 95.2% | 100% | 1 (6.03) | 3 (5.61) |
| Claude Sonnet 3.7 | 200K | 1.0/0.85 | 1.0/0.85 | 85.7% | 85.7% | 8 (5.38) | 7 (5.37) |
| Pixtral Large | 128K | 0.9/0.62 | 1.0/0.85 | 47.1% | 85.7% | 37 (4.91) | 50 (4.67) |
| Gemini 2.5 Pro | 1M | 0.9/0.57 | 1.0/0.85 | 38.1% | 85.7% | 5 (5.45) | 27 (4.88) |
Secure Code Generation
Secure code generation studies how to produce code that meets functional requirements while avoiding security vulnerabilities.
See all 48 papers