构建首个代码代理安全评估基准,测试其生成和执行危险代码的能力。
RedCode: Risky Code Execution and Generation Benchmark for Code Agents
- 设计两类测试:执行风险代码与生成有害代码的指令响应
- 4050个真实漏洞案例覆盖25类威胁,评估结果揭示模型拒识率差异
- 越强的模型越易生成复杂恶意代码,需加强安全评测机制
随着代码代理在AI辅助编程中的广泛应用,生成或执行危险代码的安全隐患已成为实际部署的主要障碍。为提供全面且实用的安全评估,我们提出RedCode基准,包含两部分:(1) RedCode-Exec 提供4050个涉及Python和Bash的任务,涵盖8个领域中的25类关键漏洞,以多样输入格式(代码片段、自然文本)测试代码代理对危险执行的识别与处理能力,并配套Docker环境与评估指标;(2) RedCode-Gen 提供160个带函数签名和文档字符串的提示,评估代码代理是否会在指令下生成有害代码。基于19个LLM的三类代理框架实证发现:代理更可能拒绝操作系统级危险操作,但对技术性错误代码拒绝率低,自然语言描述的危险操作拒识率低于代码形式;更强的基模型(如GPT4)在生成复杂有效恶意软件方面表现更优。研究强调必须对各类代码代理进行严格安全评估。数据集与代码已开源。
原文摘要 · Abstract (English)
With the rapidly increasing capabilities and adoption of code agents for AI-assisted coding, safety concerns, such as generating or executing risky code, have become significant barriers to the real-world deployment of these agents. To provide comprehensive and practical evaluations on the safety of code agents, we propose RedCode, a benchmark for risky code execution and generation: (1) RedCode-Exec provides challenging prompts that could lead to risky code execution, aiming to evaluate code agents' ability to recognize and handle unsafe code. We provide a total of 4,050 risky test cases in Python and Bash tasks with diverse input formats including code snippets and natural text. They covers 25 types of critical vulnerabilities spanning 8 domains (e.g., websites, file systems). We provide Docker environments and design corresponding evaluation metrics to assess their execution results. (2) RedCode-Gen provides 160 prompts with function signatures and docstrings as input to assess whether code agents will follow instructions to generate harmful code or software. Our empirical findings, derived from evaluating three agent frameworks based on 19 LLMs, provide insights into code agents' vulnerabilities. For instance, evaluations on RedCode-Exec show that agents are more likely to reject executing risky operations on the operating system, but are less likely to reject executing technically buggy code, indicating high risks. Risky operations described in natural text lead to a lower rejection rate than those in code format. Additionally, evaluations on RedCode-Gen show that more capable base models and agents with stronger overall coding abilities, such as GPT4, tend to produce more sophisticated and effective harmful software. Our findings highlight the need for stringent safety evaluations for diverse code agents. Our dataset and code are available at https://github.com/AI-secure/RedCode.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。