arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2411.07781cs.SEcs.AI
收藏

RedCode:面向代码智能体的风险代码执行与生成基准

RedCode: Risky Code Execution and Generation Benchmark for Code Agents

University of Chicago(芝加哥大学);University of Illinois Urbana-Champaign(伊利诺伊大学厄巴纳-香槟分校);Lapis Labs(拉皮斯实验室);Virginia Tech(弗吉尼亚理工大学);Microsoft Research(微软研究院);University of California Berkeley(加州大学伯克利分校)

Chengquan Guo, Xun Liu, Chulin Xie, Andy Zhou, Yi Zeng, Zinan Lin, Dawn Song, Bo Li

AI总结:

针对代码智能体生成或执行风险代码的安全问题,提出包含执行与生成两个子任务的 RedCode 基准,通过大量测试用例评估发现现有智能体存在显著安全风险,强调需加强安全评估。

摘要:

随着 AI 辅助编程代码智能体能力的快速提升和广泛采用,生成或执行风险代码等安全问题已成为这些智能体实际部署的重大障碍。为了对代码智能体的安全性提供全面且实用的评估,我们提出了 RedCode,一个用于风险代码执行和生成的基准:(1) RedCode-Exec 提供可能导致风险代码执行的挑战性提示,旨在评估代码智能体识别和处理不安全代码的能力。我们提供了总计 4,050 个风险测试用例,涵盖 Python 和 Bash 任务,输入格式多样,包括代码片段和自然文本。这些测试用例覆盖了跨越 8 个领域(如网站、文件系统)的 25 种关键漏洞。我们提供了 Docker 环境并设计了相应的评估指标来评估其执行结果。(2) RedCode-Gen 提供了 160 个带有函数签名和文档字符串的提示作为输入,以评估代码智能体是否会遵循指令生成有害代码或软件。我们基于 19 个 LLM 评估了三种智能体框架,所得的经验发现为代码智能体的漏洞提供了深刻见解。例如,RedCode-Exec 上的评估表明,智能体更有可能拒绝在操作系统上执行风险操作,但不太可能拒绝执行技术上存在缺陷的代码,这表明存在高风险。以自然文本描述的风险操作比代码格式的风险操作拒绝率更低。此外,RedCode-Gen 上的评估显示,能力更强的基础模型和具有更强整体编程能力的智能体(如 GPT4)往往会产生更复杂、更有效的有害软件。我们的发现强调了对各种代码智能体进行严格安全评估的必要性。我们的数据集和代码可在 https://github.com/AI-secure/RedCode 获取。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑