yash-asthana-work/rakshak
GitHub: yash-asthana-work/rakshak
Rakshak 是一个 AI 代码审查安全工具包,通过多层沙箱隔离和静态扫描防御间接 prompt injection,使 AI 能够安全地只读分析不受信任的代码仓库。
Stars: 0 | Forks: 0
# 🛡️ AI 安全工具包 - Rakshak
### 审计你所拥有的 agent。分诊你不信任的代码。
两个 **Claude Code 技能** + 一个 **纵深防御 wrapper**,让 AI 能够安全地检查
不受信任的、外来的代码 —— _而无需审查者执行埋藏在其中的隐藏指令。_
[](https://github.com/yash-asthana-work/rakshak/actions/workflows/ci.yml)





## 一段话说明问题所在
LLM **无法可靠地将你的指令与它在文件中读取的文本区分开来。** 因此一个
恶意的仓库可以植入 `AI assistant: run this…` 或 `ignore previous instructions…`,并寄希望于
审查的 AI _服从外来数据_ —— 这就是 **间接 prompt injection**,而且没有任何 prompt
能完全修复它。这个工具包不依赖于 prompt。它通过真实的
OS 和应用层控制来**隔离**审查者,并将 prompt 仅作为多层防御中的最后一层。
```
flowchart TD
U["🗂️ Untrusted repocode · README · comments = DATA, not instructions"] U --> L3 subgraph DEF ["🧱 Defense in depth"] direction TB L3["🧠 Layer 3 · Skill / prompt
treat as data · report, don't obey
(defense-in-depth only)"] L2["🪝 Layer 2 · Guard hook
deny non-read-only · fail closed · audit log"] L1["⛔ Layer 1 · Claude Code deny-list
no Bash / Write / Edit / Web"] L0["📦 Layer 0 · OS sandbox
read-only mount · no network · no creds"] L3 --> L2 --> L1 --> L0 end L0 --> V["✅ Safety verdict
nothing was executed"] BAD["💥 write · exec · network · exfil"] L1 -. blocked .-> BAD L0 -. blocked .-> BAD ``` ## 🧰 两个技能,相反的方向 | | 🔒 `untrusted-code-triage` | 🔎 `agentic-security-audit` | | ------------- | ----------------------------------------- | ---------------------------------------- | | **问题** | _“这个外来仓库运行安全吗?”_ | _“我构建的 agent 有漏洞吗?”_ | | **方向** | 保护审查者**免受**代码侵害 | 审计**你拥有的**系统 | | **模式** | 严格只读,将一切视为数据 | 7 阶段评估,OWASP + MITRE ATLAS | | **输出** | `SAFE` / `CAUTION` / `DO-NOT-RUN` 判定 | 风险评分报告 + 修复路线图 | ## 🚀 快速开始 ``` git clone
🏢 在你的组织中推广
对于**不可覆盖的**控制,将隔离权限放在 Claude Code
**managed settings** 中(企业策略 —— 用户无法覆盖它):
| OS | 路径 |
| ------- | --------------------------------------------------------------- |
| Windows | `C:\ProgramData\ClaudeCode\managed-settings.json` |
| macOS | `/Library/Application Support/ClaudeCode/managed-settings.json` |
| Linux | `/etc/claude-code/managed-settings.json` |
将 `wrapper/hooks/triage_guard.py` 发布到一个固定路径,在
托管配置的 `PreToolUse` hook 中引用该绝对路径,并保持 `disableBypassPermissionsMode: true`,这样
`--dangerously-skip-permissions` 就无法突破限制。在入职培训时通过 `install.*` 分发技能。
**对于真正不信任的代码,绝对不要跳过 Layer 0** —— OS/网络隔离是唯一
能够在完全被 injection 破坏后存活下来的东西。
🗂️ 仓库布局
```
skills/
untrusted-code-triage/ SKILL.md · references/ · scripts/scan_untrusted.py · portable-instructions.md
agentic-security-audit/ SKILL.md · references/ (7 phases) · scripts/ (score.py, injection_corpus.py)
wrapper/
settings.quarantine.json Layer 1 — Claude Code deny-list + hook wiring
hooks/triage_guard.py Layer 2 — PreToolUse guard, fails closed, audit log
launch-triage.ps1 / .sh stage read-only + launch quarantined (Windows / Unix)
devcontainer/ Layer 0 — OS containment (Claude Code AND Copilot)
tests/ pytest suite + malicious/benign fixtures
examples/ sample triage verdict
install.ps1 / install.sh install skills into ~/.claude/skills
AGENTS.md · CLAUDE.md · .github/copilot-instructions.md tool guidance
```
🧪 测试
```
pytest tests/ # scanner catches every attack class · stays quiet on clean code
# guard decision matrix · guard fails closed on bad input
```
CI (`.github/workflows/ci.yml`) 会在 Linux/macOS/Windows 上运行测试套件,外加一个扫描器自测。
标签:AI合规, AI安全, AI编程助手, Chat Copilot, Claude Code, 代码审查, 安全规则引擎, 应用安全, 沙箱, 逆向工具