reznik99/Sandbox
GitHub: reznik99/Sandbox
一个基于 Podman 的安全沙箱容器,预配置多层安全限制,用于隔离运行不可信脚本和 AI 编程助手。
Stars: 0 | Forks: 0
# 沙箱
一个用于运行不可信脚本的安全 Podman 容器。
## 包含工具
| 工具 | 软件包 |
| -------------- | ---------------------- |
| Node.js 24 | nodejs24, nodejs24-npm |
| Go | golang |
| GCC/G++ | gcc, gcc-c++ |
| Make | make |
| Git | git |
| SSH | openssh-clients |
| GPG | gnupg2 |
| OpenSSL | openssl |
| curl | curl |
| wget | wget |
| Vim | vim |
| fzf | fzf |
| lsd | lsd |
| ripgrep | ripgrep |
| find | findutils |
| ps/top | procps-ng |
| Claude Code | claude.ai/install.sh |
## 构建镜像
```
podman build \
--build-arg USER_ID=$(id -u) \
--build-arg GROUP_ID=$(id -g) \
-t sandbox .
```
## Shell 别名
将这些添加到您的 `~/.bashrc` 或 `~/.profile`:
```
# 完全隔离的沙箱(无共享主机文件)
alias sandbox='podman start -ai sandbox 2>/dev/null || podman run -it \
--name sandbox \
--cap-drop=ALL \
--security-opt=no-new-privileges \
--userns=keep-id \
--pids-limit=512 \
--memory=2g \
--cpus=10 \
localhost/sandbox bash'
# 仅挂载 ~/Code 的沙箱
alias sandbox-code='podman start -ai sandbox-code 2>/dev/null || podman run -it \
--name sandbox-code \
--cap-drop=ALL \
--security-opt=no-new-privileges \
--userns=keep-id \
--pids-limit=512 \
--memory=4g \
--cpus=10 \
-v ~/Code:/workspace:rw,z \
-w /workspace \
localhost/sandbox bash'
# 停止沙箱
alias sandbox-stop='podman stop sandbox sandbox-code'
# 销毁沙箱(仅容器,保留镜像)
alias sandbox-nuke='podman rm -f sandbox sandbox-code'
# 从头开始重新构建镜像
alias sandbox-rebuild='podman build --no-cache -t sandbox .'
```
## 用法
```
# 进入完全隔离的沙箱
sandbox
# 进入挂载 ~/Code 到 /workspace 的沙箱
sandbox-code
# 停止所有沙箱容器
sandbox-stop
# 销毁所有沙箱容器并在下次全新开始
sandbox-nuke
# 重新构建镜像(例如在编辑 Dockerfile 后)
sandbox-rebuild
```
## 安全性
容器运行时包含:
- `--cap-drop=ALL` — 丢弃所有 Linux capabilities
- `--security-opt=no-new-privileges` — 防止权限提升
- `--userns=keep-id` — 将主机 UID 映射到容器中
- `--pids-limit=512` — 限制 fork 炸弹
- `--memory=2g`/`4g` — 限制内存使用
- `--cpus=10` — 将 CPU 使用限制为 10 核
- 容器内的非 root 用户 (`sandbox`)
标签:AI 安全, Claude, CVE检测, DevSecOps, DLL 劫持, Docker, GCC, GNU通用公共许可证, Golang, JSONLines, Linux 容器, Node.js, Podman, Web截图, 上游代理, 代码执行环境, 大语言模型, 安全编程, 安全防御评估, 容器安全, 应用安全, 开发环境, 提示词注入防护, 攻击缓解, 数字取证, 沙箱, 爆裂半径控制, 网络安全, 自动化脚本, 虚拟化, 请求拦截, 隐私保护, 隔离运行, 零信任