ian-flores/securetools

GitHub: ian-flores/securetools

为 R 语言 LLM 代理提供预构建的安全强化工具定义,通过路径限定、SQL 参数化、域名白名单和速率限制等机制防止 AI 代理越权操作。

Stars: 0 | Forks: 0

# securetools [![R-CMD-check](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/532c95a862142553.svg)](https://github.com/ian-flores/securetools/actions/workflows/R-CMD-check.yaml) [![Codecov test coverage](https://codecov.io/gh/ian-flores/securetools/graph/badge.svg)](https://app.codecov.io/gh/ian-flores/securetools) [![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) [![pkgdown](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/137224c361142554.svg)](https://ian-flores.github.io/securetools/) 适用于 R LLM 代理的安全强化工具定义。预构建的 [securer](https://github.com/ian-flores/securer) 工具工厂,支持 路径范围限定、参数化 SQL、域名允许列表、大小限制和速率 限制。 ## 为什么选择 securetools? LLM 可以调用 `system()`、写入任意路径并运行任意 SQL。 securetools 提供了预构建的、安全强化的工具包装器,用于强制执行 沙盒化、路径限制和查询验证——这样您就可以赋予 AI 代理真实的能力,而无需赋予它们系统的完全控制权。 ## secure-r-dev 生态系统的一部分 securetools 是用于在 R 中构建受治理 AI 代理的 7 包生态系统的一部分: ``` ┌─────────────┐ │ securer │ └──────┬──────┘ ┌────────────────┼─────────────────┐ │ │ │ ┌───────▼────────┐ ┌───▼──────────┐ ┌───▼──────────────┐ │>>> securetools<<<│ │ secureguard │ │ securecontext │ └───────┬────────┘ └───┬──────────┘ └───┬──────────────┘ └────────────────┼─────────────────┘ ┌──────▼───────┐ │ orchestr │ └──────┬───────┘ ┌────────────────┼─────────────────┐ │ │ ┌──────▼──────┐ ┌──────▼──────┐ │ securetrace │ │ securebench │ └─────────────┘ └─────────────┘ ``` securetools 提供了预构建的、安全强化的工具定义,可直接插入 securer 会话中。它与 secureguard 和 securecontext 一起位于中间层,为代理提供对文件、SQL、URL 和计算的安全访问。 | 包 | 角色 | |---------|------| | [securer](https://github.com/ian-flores/securer) | 具有工具调用 IPC 的沙盒化 R 执行 | | [securetools](https://github.com/ian-flores/securetools) | 预构建的安全强化工具定义 | | [secureguard](https://github.com/ian-flores/secureguard) | 输入/代码/输出护栏(注入、PII、机密) | | [orchestr](https://github.com/ian-flores/orchestr) | 基于图的代理编排 | | [securecontext](https://github.com/ian-flores/securecontext) | 文档分块、嵌入、RAG 检索 | | [securetrace](https://github.com/ian-flores/securetrace) | 结构化跟踪、Token/成本核算、JSONL 导出 | | [securebench](https://github.com/ian-flores/securebench) | 具有精确率/召回率/F1 指标的护栏基准测试 | ## 安装 ``` # install.packages("pak") pak::pak("ian-flores/securetools") ``` ## 快速入门 ``` library(securetools) library(securer) # 创建具有安全约束的 tools calc <- tool_calculator() reader <- tool_read_file(allowed_dirs = "/data", max_file_size = "50MB") sql <- tool_query_sql(conn = con, allowed_tables = c("users", "orders")) # 与 SecureSession 一起使用 session <- SecureSession$new(tools = list(calc, reader, sql)) session$execute('calculator(expression = "sqrt(144) + 2^3")') #> [1] 20 session$close() ``` ## 可用工具 | 工具 | 工厂 | 安全特性 | |------|---------|-------------------| | 计算器 | `tool_calculator()` | AST 验证,无代码注入 | | 数据概况 | `tool_data_profile()` | 对大数据进行行采样 | | 读取文件 | `tool_read_file()` | 路径范围限定,大小限制 | | 写入文件 | `tool_write_file()` | 路径范围限定,覆盖保护 | | SQL 查询 | `tool_query_sql()` | 表允许列表,参数化查询 | | URL 获取 | `tool_fetch_url()` | 域名允许列表,速率限制 | | 绘图 | `tool_plot()` | 路径范围限定,输出大小限制 | | R 帮助 | `tool_r_help()` | 包允许列表 | ## 设计原则 - **工厂函数**:`tool_read_file(allowed_dirs = "/data")` 强制执行 显式的安全配置 - **父进程端强制执行**:工具约束在宿主进程中运行, 而非在沙盒中。即使沙盒被绕过,工具保护依然有效 - **无原始 SQL**:结构化查询接口使得注入在结构上 不可能发生 - **符号链接解析**:在路径前缀检查之前使用 `normalizePath()` 可防止符号链接逃逸 - **AST 遍历**:计算器验证的是表达式树,而不是字符串 ## 文档 - `vignette("securetools")` -- 入门指南:工具工厂、安全 配置以及如何与 securer 会话配合使用 - `vignette("agent-integration")` -- 将 securetools 集成到 LLM 代理工作流的端到端示例 - [pkgdown 站点](https://ian-flores.github.io/securetools/) -- 完整的 API 参考和渲染的 vignettes ## 贡献 发现了错误或有功能请求?请在 GitHub 上 [提交 issue](https://github.com/ian-flores/securetools/issues)。 欢迎通过 pull request 进行贡献。 ## 许可证 MIT
标签:AI代理, AI治理, API安全, API密钥检测, C2, CISA项目, JSON输出, Prompt注入防护, R语言, SQL参数化, SQL注入防护, Streamlit, XML 请求, 代码安全, 域名白名单, 多线程, 大语言模型安全, 子域名枚举, 安全工具库, 安全开发, 安全沙箱, 安全生态系统, 安全防护, 工具定义, 提示词安全, 机密管理, 漏洞枚举, 系统安全, 结构化查询, 网络安全, 自动化payload嵌入, 自动化安全, 被动侦察, 访问控制, 路径限制, 输入验证, 隐私保护