feat: add tool script safety guard#113
Open
xyxhhhhh wants to merge 1 commit into
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #113 +/- ##
==========================================
Coverage ? 87.84235%
==========================================
Files ? 442
Lines ? 42245
Branches ? 0
==========================================
Hits ? 37109
Misses ? 5136
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
ccf18ad to
8bc9647
Compare
Author
|
I have read the CLA Document and I hereby sign the CLA |
Rook1ex
added a commit
to trpc-group/cla-database
that referenced
this pull request
Jul 2, 2026
8bc9647 to
343a75c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
Resolves #90
本 PR 实现 了Tool Script Safety Guard,用于在 Tool / Skill / MCP Tool /
CodeExecutor 执行脚本或命令前进行安全扫描、策略判断、拦截和审计。
主要能力:
allow/deny/needs_human_review三类决策recommendation
tool.safety.*attributesBashTool和UnsafeLocalCodeExecutor提供 opt-in 接入,不改变默认历史行为
风险覆盖
已覆盖的风险类型:
.env、~/.ssh、凭据文件访问等curl、wget、requests、aiohttp、socket、非白名单域名访问等
subprocess、os.system、shell 管道、命令替换、后台进程、提权命令等
pip install、python -m pip install、npm install、apt install等兼容性
核心执行链路接入采用 opt-in 方式,避免破坏现有默认行为。
BashTool和UnsafeLocalCodeExecutor默认保持原有执行逻辑。用户可以通过参数enable_safety_guard=True显式启用安全扫描。启用后:
deny会在执行前阻断脚本或命令needs_human_review默认只记录到safety_report,不阻断执行block_on_review=True验证
已通过本 PR 相关测试:
python -m pytest tests/tools/safety -qpython -m pytest tests/file_tools/test_bash_tool.py tests/code_executors/ local/test_unsafe_local_code_executor.py tests/code_executors/ test_local_unsafe_local_code_executor.py -q同时验证了 31 条公开样例均可扫描并输出结构化报告。
文档
新增
examples/tool_safety/README.md,说明规则体系、策略配置、CLI 使用方式、Filter / Wrapper / 核心链路 opt-in 接入方式、报告和审计日志格式、OpenTelemetry
字段、已知限制,以及为什么静态扫描不能替代沙箱隔离。