GreyhavenHQ/greywall

GitHub: GreyhavenHQ/greywall

一款跨平台的轻量级命令行沙箱,专为安全运行 AI 编码 Agent 设计,支持权限自动学习和透明代理流量管控。

Stars: 47 | Forks: 12

# Greywall Greywall 将命令封装在默认拒绝(deny-by-default)的沙箱中。默认情况下,文件系统访问仅限于当前目录。使用 `--learning` 追踪命令的其他需求并自动生成配置文件。所有网络流量透明地通过 [greyproxy](https://github.com/GreyhavenHQ/greyproxy) 重定向,这是一个带有实时允许/拒绝仪表板的默认拒绝透明代理。运行 `greywall setup` 可自动安装 greyproxy。 *支持 Linux 和 macOS。详情请参阅 [平台支持](docs/platform-support.md)。* https://github.com/user-attachments/assets/7d62d45d-a201-4f24-9138-b460e4c157a8 ``` # 检查 greywall 安装是否正常 greywall check # 沙箱化命令(默认拒绝网络 + 文件系统) greywall -- curl https://example.com # 了解命令所需的文件系统访问权限,然后自动生成配置文件 greywall --learning -- opencode # 拦截危险命令 greywall -c "rm -rf /" # → blocked by command deny rules ``` ## 安装 **Homebrew (macOS):** ``` brew tap greyhavenhq/tap brew install greywall ``` 这也会将 [greyproxy](https://github.com/GreyhavenHQ/greyproxy) 作为依赖项安装。 **Linux / Mac:** ``` curl -fsSL https://raw.githubusercontent.com/GreyhavenHQ/greywall/main/install.sh | sh ```
其他安装方法 **Go install:** ``` go install github.com/GreyhavenHQ/greywall/cmd/greywall@latest ``` **从源码构建:** ``` git clone https://github.com/GreyhavenHQ/greywall cd greywall make setup && make build ```
**Linux 依赖项:** - `bubblewrap` - 无容器沙箱(必需) - `socat` - 网络桥接(必需) 使用 `greywall check` 检查依赖状态。 ## 用法 ### 基本命令 ``` # 在所有网络被拦截的情况下运行(默认) greywall -- curl https://example.com # 通过 Shell expansion 运行 greywall -c "echo hello && ls" # 通过 SOCKS5 代理路由 greywall --proxy socks5://localhost:1080 -- npm install # 暴露端口以供入站连接(例如 dev servers) greywall -p 3000 -c "npm run dev" # 启用 debug 日志记录 greywall -d -- curl https://example.com # 监控沙箱违规行为 greywall -m -- npm install # 显示可用的 Linux security features greywall --linux-features # 显示版本 greywall --version # 检查依赖项、security features 和 greyproxy 状态 greywall check # 安装并启动 greyproxy greywall setup ``` ### Agent 配置文件 Greywall 内置了流行 AI 编码 Agent(Claude、Codex、Cursor、Aider、Goose、Gemini、OpenCode、Amp、Cline、Copilot、Kilo、Auggie、Droid)和工具链(Node、Python、Go、Rust、Java、Ruby、Docker)的配置文件。 首次运行时,Greywall 会显示该配置文件允许的内容,并让你选择应用、编辑或跳过: ``` $ greywall -- claude [greywall] Running claude in a sandbox. A built-in profile is available. Without it, only the current directory is accessible. Allow read: ~/.claude ~/.claude.json ~/.config/claude ~/.local/share/claude ~/.gitconfig ... + working dir Allow write: ~/.claude ~/.claude.json ~/.cache/claude ~/.config/claude ... + working dir Deny read: ~/.ssh/id_* ~/.gnupg/** .env .env.* Deny write: ~/.bashrc ~/.zshrc ~/.ssh ~/.gnupg [Y] Use profile (recommended) [e] Edit first [s] Skip (restrictive) [n] Don't ask again > ``` 使用 `--profile` 组合 Agent 和工具链配置文件: ``` # Agent + Python toolchain(允许访问 ~/.cache/uv、~/.local/pipx 等) greywall --profile claude,python -- claude # Agent + 多个 toolchains greywall --profile opencode,node,go -- opencode # 列出所有可用和已保存的配置文件 greywall profiles list ``` ### 学习模式 Greywall 可以追踪命令的文件系统访问并自动生成配置文件: ``` # 在 learning mode 下运行 - 通过 strace 追踪文件访问 greywall --learning -- opencode # 列出生成的配置文件 greywall profiles list # 显示配置文件内容 greywall profiles show opencode # 下次运行自动加载学习到的配置文件 greywall -- opencode ``` ### 配置 Greywall 默认从 `~/.config/greywall/greywall.json` 读取配置(macOS 上为 `~/Library/Application Support/greywall/greywall.json`)。 ``` { // Route traffic through an external SOCKS5 proxy "network": { "proxyUrl": "socks5://localhost:1080", "dnsAddr": "localhost:5353" }, // Control filesystem access "filesystem": { "defaultDenyRead": true, "allowRead": ["~/.config/myapp"], "allowWrite": ["."], "denyWrite": ["~/.ssh/**"], "denyRead": ["~/.ssh/id_*", ".env"] }, // Block dangerous commands "command": { "deny": ["git push", "npm publish"] } } ``` 使用 `greywall --settings ./custom.json` 指定不同的配置文件。 默认情况下,流量通过 `localhost:43052` 的 GreyProxy SOCKS5 代理路由,DNS 通过 `localhost:43053`。 ## 平台支持 | 功能 | Linux | macOS | |---------|:-----:|:-----:| | **沙箱引擎** | bubblewrap | sandbox-exec (Seatbelt) | | **文件系统默认拒绝(读/写)** | ✅ | ✅ | | **系统调用过滤** | ✅ (seccomp) | ✅ (Seatbelt) | | **文件系统访问控制** | ✅ (Landlock + bubblewrap) | ✅ (Seatbelt) | | **违规监控** | ✅ (eBPF) | ✅ (Seatbelt 拒绝日志) | | **透明代理(全流量捕获)** | ✅ (tun2socks + TUN) | ❌ | | **DNS 捕获** | ✅ (DNS 桥接) | ❌ | | **通过环境变量代理(SOCKS5 / HTTP)** | ✅ | ✅ | | **网络隔离** | ✅ (network namespace) | N/A | | **命令允许/拒绝列表** | ✅ | ✅ | | **环境变量净化** | ✅ | ✅ | | **学习模式** | ✅ (strace) | ✅ (eslogger, 需要 sudo) | | **PTY 支持** | ✅ | ✅ | | **外部依赖** | bwrap, socat | 无 | 有关更多详细信息,请参阅 [平台支持](docs/platform-support.md)。 Greywall 也可以作为 [Go package](docs/library.md) 使用。 ## 文档 - [文档索引](docs/README.md) - [快速入门指南](docs/quickstart.md) - [为什么选择 Greywall](docs/why-greywall.md) - [配置参考](docs/configuration.md) - [学习模式](docs/learning.md) - [安全模型](docs/security-model.md) - [架构](ARCHITECTURE.md) - [平台支持](docs/platform-support.md) - [Linux 安全功能](docs/linux-security-features.md) - [AI Agent 集成](docs/agents.md) - [库使用(Go)](docs/library.md) - [故障排除](docs/troubleshooting.md) ## 致谢 Greywall 是 [Fence](https://github.com/Use-Tusk/fence) 的分支,最初由 [Tusk AI, Inc](https://github.com/Use-Tusk) 的 [JY Tan](https://github.com/jy-tan) 创建。 版权所有 2025 Tusk AI, Inc。根据 Apache License 2.0 授权。 灵感来自 Anthropic 的 [sandbox-runtime](https://github.com/anthropic-experimental/sandbox-runtime)。
标签:Bubblewrap, Docker镜像, EVTX分析, Go语言, JSONLines, macOS安全, Streamlit, 动态配置, 安全隔离, 文件系统隔离, 日志审计, 沙箱, 灰度代理, 程序破解, 网络流量控制, 自动化配置生成, 行为监控, 访问控制, 进程隔离, 透明代理, 零信任, 默认拒绝策略