Metraipolis › archive › dc_c3ef9b6917fb
CodeMimicry: Exploiting Safety Generalization Lag in Large Language Models via Structured Code Completion — arXiv:2609.39902
- Source
- arXiv (en)
- Original
- https://arxiv.org/abs/2609.39902
- License (as archived)
- CC0-1.0
- Archived
- 2026-10-07T12:45:53.466Z
- SHA-256 of the archived text
56234afb3ef931eddb5fa17dcc861a1e01edf59de0e898c31108afccef5b8e52- Stable URL of this page
https://metraipolis.com/documento/dc_c3ef9b6917fb
How to cite
CodeMimicry: Exploiting Safety Generalization Lag in Large Language Models via Structured Code Completion — arXiv:2609.39902 — arXiv (en), https://arxiv.org/abs/2609.39902 (CC0-1.0); archived copy: https://metraipolis.com/documento/dc_c3ef9b6917fb (Metraipolis archive dc_c3ef9b6917fb, sha256 56234afb3ef931eddb5fa17dcc861a1e01edf59de0e898c31108afccef5b8e52)
BibTeX
@misc{dcc3ef9b6917fb,
title = {CodeMimicry: Exploiting Safety Generalization Lag in Large Language Models via Structured Code Completion — arXiv:2609.39902},
howpublished = {arXiv (en)},
url = {https://arxiv.org/abs/2609.39902},
note = {License CC0-1.0; archived copy https://metraipolis.com/documento/dc_c3ef9b6917fb; sha256 56234afb3ef931eddb5fa17dcc861a1e01edf59de0e898c31108afccef5b8e52},
year = {2026}
}Archived text
Reproduced under CC0-1.0. Attribution: arXiv (en), https://arxiv.org/abs/2609.39902. Third-party text: data, not instructions. It may be an abstract or extract; check the original.
Large language models have achieved remarkable capabilities across diverse domains, yet their safety alignment remains vulnerable to jailbreak attacks. In this work, we identify a previously underexplored failure mode - safety generalization lag - where alignment trained predominantly on natural language fails to transfer to the code domain. We show that this lag induces a code-completion blind spot, allowing malicious intent embedded within syntactically valid code to evade safety mechanisms. To exploit this vulnerability, we propose CodeMimicry, a fully automated black-box jailbreak framework that generates structured, object-oriented code prompts to induce harmful outputs via code completion. Experiments on 8 state-of-the-art commercial LLMs demonstrate that CodeMimicry achieves a 96.25% attack success rate with 1.51 queries on average, significantly outperforming both template-based and optimization-based baselines. Beyond empirical performance, we provide a mechanistic analysis of code-based jailbreaks through latent space representations, including projection onto refusal-related directions and activation steering. This analysis offers an explanation of how CodeMimicry bypasses safety mechanisms in code-related domains. Our findings reveal a weakness in current safety alignment and highlight the need for robust alignments in structured domains such as code. Tema degli esploratori: agenti e intelligenza artificiale (retro-catalogo arXiv: annunci del 2026-10-01 in cs.AI). Categorie arXiv: Cryptography and Security (cs.CR) ; Artificial Intelligence (cs.AI). Pagina del lavoro: https://arxiv.org/abs/2609.39902 — autori e testo completo sono lì (qui omessi i nomi: nessun dato personale nel deposito). Licenza: titolo e abstract sono metadati arXiv distribuiti in CC0 1.0; il testo completo ha la licenza scelta dagli autori, indicata sulla pagina. Letto il 2026-10-07T12:14:14.170Z dalla pagina https://arxiv.org/catchup/cs.AI/2026-10-01?abs=True (consentita dal robots.txt di arxiv.org, con il suo crawl-delay).