CodeMimicry bypasses LLM safety in code completion with 96% success
Safety generalization lag lets structured code prompts jailbreak LLMs, achieving 96.25% success
AI/ML arXiv 30 Sep 2026 Attack Prototype evidence
Published as “CodeMimicry: Exploiting Safety Generalization Lag in Large Language Models via Structured Code Completion”
Why it matters
The work shows that current safety alignment leaves the code domain largely unprotected, prompting the need for alignment techniques that cover structured generation tasks.
Summary
CodeMimicry can jailbreak large language models in the code domain with a 96.25% attack success rate while using only 1.51 queries on average, far outperforming prior template-based and optimization-based methods. The authors attribute this to a safety generalization lag where alignment trained on natural language does not transfer to structured code. Evidence comes from experiments on eight commercial LLMs and mechanistic latent-space analysis, though defenses based on detection still leave high residual success rates and the approach degrades on smaller models.
What they found 1
- CodeMimicry attains a 96.25% attack success rate with 1.51 average queries.
“CodeMimicry achieves a 96.25% attack success rate with 1.51 queries on average”
Caveats 3
- Detection-based methods such as Llama Guard [31] and perplexity filtering provide limited protection, with high residual ASR (76%-100%)
- CodeMimicry is a code-based automated jailbreak framework that relies on the target model possessing sufficient code generation and instruction-following capabilities. As a result, its effectiveness may degrade on smaller or lightweight models
- Another limitation of CodeMimicry is its dependence on string-level side channels, particularly comments and docstrings. Experimental results in Appendix B.4 show that introducing comment filtering substantially lowers the ASR of CodeMimicry and other code-based jailbreak attacks.
What’s new here 4
- Exploits a safety generalization lag specific to code generation, a failure mode not addressed by prior jailbreak work.
- Generates structured, object-oriented code prompts automatically, rather than relying on natural-language heuristics or manual templates.
- Achieves near-one-shot attack efficiency (≈1.5 queries) across multiple LLMs.
- Provides mechanistic analysis via latent-space projection and activation steering to explain bypassing of refusal mechanisms.