Agent Sandbox 三國誌:BoxLite vs Fence vs Docker 點樣揀?
你有冇發覺,而家 AI coding agent 生成嘅 code 越來越唔似人寫?唔係讚佢——係指佢哋越來越擅長寫出你唔敢直接執行嘅嘢。rm -rf /、往外送 API key、畀你自己嘅 credential 送去不知名 endpoint。呢啲唔係理論風險,而係 daily reality。所以 agent sandbox 由「最好有」變成「一定要有」。但個問題係:市場上所謂嘅 sandbox solution,根本係三種完全唔同嘅嘢。
三種路線,三種哲學
BoxLite 行 microVM 路線——每個 agent session 俾一個獨立 kernel,KVM 或者 Hypervisor.framework 做 hardware isolation。Boot time 宣稱 <50ms(cached 之後),memory overhead 每盒大約 70-140MB(kernel + VM overhead + container)。冇 daemon,唔使 root,可以當 library 直接 embed 入你嘅 application。Stateful by default——裝咗嘅 package、create 咗嘅 file,stop 咗 restart 返全部喺度。呢個設計哲學叫「SQLite of sandboxing」——細、嵌入、唔使你管 infrastructure。
Fence 行另一條路:無容器。佢直接用 bubblewrap(Linux)或 sandbox-exec(macOS)嚟限制 process 嘅 network 同 filesystem 權限。Overhead 細到誇張——每個 command 大約 5-10ms 延遲,memory 只係 2-5MB。唔使 VM、唔使 container runtime、唔使 daemon。純粹係用 OS 層面嘅 namespace 同 seccomp 做限制。Fence 嘅定位係 defense-in-depth 果層——你已經有 Docker 或者 VM?再加一層 Fence 做 command blocking 同 network isolation。
Docker 就唔使多介紹。Container 共享 host kernel,startup 100-500ms(image cached 之後),overhead 接近零。但 security model 最弱——CVE-2024-21626 呢類 container escape 已經證明 shared kernel 唔足以隔離 untrusted code。而且 Docker daemon 行 root,agent 如果 breakout 咗,你成部機就 bye bye。
Benchmark 殘酷對比
先講 latency。BoxLite 官網話 <50ms boot,但呢個係 ideal condition——image cached、resource 充足嘅 local environment。第一次 boot 要 pull image,實際要 5-30 秒。之後 cached 咗的確可以 1-2 秒內搞掂。Fence 嘅 overhead 係每次 command execution 加 5-10ms——呢個數字細到可以 ignore,因為 agent 每次 LLM call 本身已經要幾秒。Docker 嘅 startup 係 100-500ms(image cached),但第一次要 pull image,同 BoxLite 差不多。
資源消耗係最大分野。Fence 開一個 sandbox 用 2-5MB memory,你開 1000 個都唔會出事。BoxLite 每盒 70-140MB——100 盒就係 7-14GB,仲未計 guest OS 自己嘅 memory 配額(預設 128MB 起跳)。Docker 中間:每 container 大約 10-30MB overhead(未計 container 入面嘅 process)。
Security 就掉轉。BoxLite 最強——三層保護:KVM/HVF hardware isolation、seccomp/sandbox-exec OS sandboxing、cgroups resource limits。每個 box 獨立 kernel,breakout 要過 hypervisor 關。Fence 中間——用 namespace isolation + seccomp,但同一個 kernel。惡意 syscall 理論上可以 escape。Docker 最弱——shared kernel,歷史上出過多次 container escape CVE。
點樣揀?
我嘅睇法係:呢三個唔係競爭對手,而係唔同 layer 嘅工具。
如果你行 production AI agent 兼執行 untrusted code——BoxLite 係唯一認真嘅選擇。Hardware isolation 唔係「好過 container」,而係「唔同層級嘅野」。Agent generate 嘅 code 嘅 unpredictability 係本質問題,你唔可以用 container 嘅 shared kernel 去解決一個需要獨立 kernel 嘅 threat model。
如果你只係想保護你嘅 development environment——唔使 full VM。Fence(或者類似嘅 ai-jail、bubblewrap wrapper)嘅 5-10ms overhead 同 2-5MB memory 意味住你可以 long run 住開住,完全唔覺得佢存在。做 coding agent 嘅 defense-in-depth 好合適。
Docker 唔應該做 agent sandbox 嘅 primary isolation layer——佢嘅角色係提供 reproducible environment(devcontainer 果種),而唔係 security boundary。如果你要用 Docker,上面應該仲有一層(BoxLite microVM 或者 Fence 嘅 process isolation)。
Final advice:唔好等出事先搞。揀一個,今日就 setup。五分鐘嘅功夫,好過聽朝起身發現 agent 幫你捐咗五百蚊去你唔認識嘅 organization。