Vấn đề
Claude Code mặc định hỏi mỗi action → mệt mỏi. Tắt hết bằng --dangerously-skip-permissions → nguy hiểm (SSH key bị leak, file bị xoá).
Sandboxing là giải pháp: giới hạn không gian Claude có thể chạy, nhưng trong đó tự do.
Kiến trúc 2 tầng
"Effective sandboxing requires BOTH filesystem and network isolation."
Phải có cả 2 đồng thời:
- Filesystem isolation: Claude chỉ đọc/ghi trong working directory hiện tại. Sửa file ngoài → bị block.
- Network isolation: Outbound traffic đi qua unix socket proxy, chỉ tới domain whitelist. Curl
evil.comđể lấy SSH key → bị chặn.
3 loại isolation
1. Filesystem
Read/write trong cwd hiện tại. Bên ngoài: read-only hoặc block.
2. Network
Tất cả outbound qua proxy. User confirm khi gặp domain lạ.
3. Process-level (OS-level)
- Linux:
bubblewrapcontainer - macOS:
seatbeltsecurity framework
Cover cả Claude Code lẫn script/subprocess mà nó spawn ra — đầy đủ.
Con số
- 84% giảm permission prompt (internal testing)
- Chặn prompt injection attack
- Block download malware, credential theft
Cách bật
Trong Claude Code, gõ /sandbox. Cấu hình:
- Allowed directories:
./src,./tests - Allowed domains:
github.com,npmjs.com,your-api.com
So với Auto mode
| Auto mode | Sandbox | |
|---|---|---|
| Cơ chế | Classifier model duyệt action | OS-level boundary cứng |
| Reliability | 17% false-negative | Cao hơn (boundary thật, không phải LLM) |
| Setup effort | 0 | Cài bubblewrap/seatbelt |
| Best for | Daily task | High-trust agent loop dài |
Combo: dùng cả 2 cho an toàn nhất.
Nguồn chính thống: anthropic.com/engineering/claude-code-sandboxing