RedCoder: Automated Multi-Turn Red Teaming for Code LLMs

📄 arXiv: 2507.22063 📥 PDF

作者: Wenjie Jacky Mo, Qin Liu, Xiaofei Wen, Dongwon Jung, Hadi Askari, Wenxuan Zhou, Zhe Zhao, Muhao Chen

分类: cs.SE, cs.AI

发布日期: 2026-07-05


💡 一句话要点

提出RedCoder以解决代码生成模型的安全性评估问题

🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)

关键词: 红队评估 代码生成 多轮对话 安全性测试 自动化工具

📋 核心要点

  1. 现有红队方法依赖大量人力,难以扩展,并且通常忽视多轮交互的特性。
  2. RedCoder通过多轮对话与代码生成模型互动,自动引导生成脆弱代码,提升了红队的效率。
  3. 实验结果显示,RedCoder在诱导脆弱性方面优于传统方法,具有更好的可扩展性和有效性。

📝 摘要(中文)

大型语言模型(LLMs)在代码生成方面展现了卓越的能力,但在对抗性环境下,这些模型容易生成脆弱或恶意代码。现有的红队方法依赖大量人力,限制了其可扩展性和实用性,并且通常忽视了真实世界AI辅助编程的多轮交互特性。为了解决这些问题,本文提出了RedCoder,一个能够与受害模型进行多轮对话的红队代理,以引导生成脆弱代码。RedCoder的构建流程始于一个多代理游戏过程,模拟对抗性互动,生成原型对话和可重用的攻击策略库。通过在这些原型对话上微调LLM,RedCoder能够自主与代码LLMs进行多轮对话,动态检索相关策略,引导对话产生脆弱输出。实验表明,该方法在诱导代码生成中的脆弱性方面优于以往的单轮和多轮红队方法,提供了一种可扩展且有效的工具来评估现代代码生成系统的安全边界。

🔬 方法详解

问题定义:本文旨在解决现有红队方法在评估代码生成模型安全性时的局限性,包括人力成本高和缺乏多轮交互能力的问题。

核心思路:RedCoder通过模拟多轮对话的方式与代码生成模型进行互动,利用生成的对话原型和攻击策略库,自动引导模型生成脆弱代码。这样的设计使得红队评估过程更加高效和灵活。

技术框架:RedCoder的构建流程包括多代理游戏过程、原型对话生成和攻击策略库的建立,随后对LLM进行微调以支持多轮对话。部署后,RedCoder能够自主与代码LLMs进行对话,动态选择策略。

关键创新:RedCoder的主要创新在于其多轮对话能力和自动化的攻击策略选择,与传统的单轮红队方法相比,显著提高了诱导脆弱性的能力。

关键设计:在技术细节上,RedCoder使用了微调的LLM作为核心,设计了多轮对话的交互流程,并构建了一个包含多种攻击策略的库,以便在对话中灵活应用。具体的参数设置和损失函数等细节在实验中进行了优化。

🖼️ 关键图片

fig_0
fig_1
fig_2

📊 实验亮点

实验结果表明,RedCoder在诱导代码生成脆弱性方面的表现优于传统的单轮和多轮红队方法,具体提升幅度达到XX%(具体数据待补充),显示出其在安全评估中的有效性和可扩展性。

🎯 应用场景

RedCoder的研究成果具有广泛的应用潜力,尤其在软件开发和安全测试领域。通过自动化的红队评估,开发者可以更有效地识别和修复代码中的安全漏洞,从而提升软件的安全性和可靠性。未来,该方法还可以扩展到其他类型的生成模型安全性评估中。

📄 摘要(原文)

Large Language Models (LLMs) for code generation (i.e., Code LLMs) have demonstrated impressive capabilities in AI-assisted software development and testing. However, recent studies have shown that these models are prone to generating vulnerable or even malicious code under adversarial settings. Existing red-teaming approaches rely on extensive human effort, limiting their scalability and practicality, and generally overlook the interactive nature of real-world AI-assisted programming, which often unfolds over multiple turns. To bridge these gaps, we present RedCoder, a red-teaming agent that engages victim models in multi-turn conversation to elicit vulnerable code. The pipeline to construct RedCoder begins with a multi-agent gaming process that simulates adversarial interactions, yielding a set of prototype conversations and an arsenal of reusable attack strategies. We then fine-tune an LLM on these prototype conversations to serve as the backbone of RedCoder. Once deployed, RedCoder autonomously engages Code LLMs in multi-turn conversations, dynamically retrieving relevant strategies from the arsenal to steer the dialogue toward vulnerability-inducing outputs. Experiments across multiple Code LLMs show that our approach outperforms prior single-turn and multi-turn red-team methods in inducing vulnerabilities in code generation, offering a scalable and effective tool for evaluating the security boundaries of modern code-generation systems.