Agent 架构文档 · Markdown
全网沙盒服务全景架构图
主题:把 2024 2026 年市面上能找到的"给代码 / Agent 用的隔离运行环境"产品和底层技术, 按"江湖位置 + 隔离原料 + 编排方式 + 上层定位"画一张可俯瞰的地图。 配套阅读: [sandbox services comparison.md](./sandbox services comparison.md) —— 横向对比表
主题:把 2024-2026 年市面上能找到的"给代码 / Agent 用的隔离运行环境"产品和底层技术, 按"江湖位置 + 隔离原料 + 编排方式 + 上层定位"画一张可俯瞰的地图。
配套阅读:
- sandbox-services-comparison.md —— 横向对比表
#目录
#一、全景一图流(按隔离原料分层)
┌──────────────────────────────────────────────────────────────────────────────┐
│ │
│ 用户 / Agent │
│ │
└──────────────────────────────────────────────────────────────────────────────┘
│
│ 一份代码、一段命令、一段 LLM 推理结果
▼
┌──────────────────────────────────────────────────────────────────────────────┐
│ 上层定位(这一层最容易混淆) │
│ │
│ ① AI agent ephemeral 沙盒 ② Agent 持久 devbox ③ Cloud IDE / CDE │
│ E2B / Modal / Vercel / Daytona / Runloop / Replit / Codespaces / │
│ CF Sandbox SDK / Riza / Morph / Together / CodeSandbox / Coder / │
│ microsandbox / Together CI Replit Agent Gitpod Flex / Sealos │
│ │
│ ④ 浏览器内 0-server ⑤ K8s / OSS 编排底座 │
│ StackBlitz WebContainer Coder / Sealos / k8s-sigs/agent-sandbox / │
│ Jupyter Enterprise Gateway │
│ │
└──────────────────────────────────────────────────────────────────────────────┘
│
│ 把"代码 + 隔离 + 网络 + 持久化"打包成一个 SaaS / SDK
▼
┌──────────────────────────────────────────────────────────────────────────────┐
│ 编排 / Fabric 层(自研 vs K8s 的分裂) │
│ │
│ 自研 fabric 基于 K8s │
│ ─────────────────────────── ─────────────────────────── │
│ E2B / Modal / Vercel Hive / Coder / Sealos / Kata-on-K8s / │
│ Cloudflare workerd / Replit k8s-sigs/agent-sandbox / │
│ Goval / CodeSandbox Pitcher / Jupyter Enterprise Gateway / │
│ Daytona control plane 但绕过 Scheduler,自己当调度器) │
│ │
└──────────────────────────────────────────────────────────────────────────────┘
│
│ 调度策略 → 决定每个沙箱跑在哪台机器上
▼
┌──────────────────────────────────────────────────────────────────────────────┐
│ 隔离原料层(这一层决定安全 / 启动速度上限) │
│ │
│ microVM (KVM-based) 用户态内核 WebAssembly │
│ ──────────────────── ──────────── ───────────── │
│ • Firecracker • gVisor (runsc) • workerd / V8 │
│ E2B / Vercel / Lambda / Modal / GKE / Cloudflare / │
│ CodeSandbox / Replit Cloud Run / ★Goalfy StackBlitz / │
│ • Cloud Hypervisor Riza │
│ • libkrun (microsandbox) Linux 容器(namespace+cgroup) │
│ • 自研 (Runloop / Morph) ──────────────────────── │
│ • runc / Docker Unikernel │
│ Kata Containers (VM-as-pod) Daytona / Codespaces / ──────────── │
│ Coder / Sealos / • Nanos / OSv │
│ CF Sandbox SDK • Nabla │
│ │
└──────────────────────────────────────────────────────────────────────────────┘
│
│ 真·物理资源
▼
┌──────────────────────────────────────────────────────────────────────────────┐
│ 裸机 / EC2 / GCE / 边缘节点 / 浏览器(WebContainer 唯一占这格) │
└──────────────────────────────────────────────────────────────────────────────┘
两条阅读捷径:
- 想知道"启动有多快"?看最底下的"隔离原料层"。WASM > microVM 快照恢复 > microVM 冷启 > gVisor > 容器 > VM。
- 想知道"安全多硬"?看同一层。Unikernel > microVM > gVisor > 容器(带 seccomp/userns)> 容器(默认)。
#二、按定位分类(用户视角)
#A. AI agent 短任务执行(来一段代码、跑、给结果、走人)
用户问题:要个能让 LLM 写完代码立刻跑的沙盒
│
┌─────────────────┬─────────┴─────────┬─────────────────┐
│ │ │ │
要全球边缘 要 GPU 要超低冷启动 想本地跑
─────────── ─────────── ─────────── ───────────
Cloudflare Modal E2B (<200ms) microsandbox
Sandbox SDK (gVisor + GPU) Daytona (~90ms) (libkrun)
Together TCI Vercel Sandbox Open Interpreter
+ Docker Sandbox
要"按 session" 要 wasm 极速 要 fork 整个 VM
─────────── ─────────── ───────────
Together TCI Riza (<10ms) Morph Infinibranch
($0.03/sess) StackBlitz Replit Snapshot Eng.
(浏览器内) CodeSandbox VM clone
#B. AI agent 持久会话(agent 跑几小时甚至几天,要保留状态)
| 厂商 | 杀手锏 |
|---|---|
| Daytona | 90ms 启动 + stateful snapshot + 开源 + 强调"为 agent 而非人" |
| Runloop | 双层隔离(VM + 容器)+ 企业 GA + Blueprint/Snapshot 双层模板 |
| Morph | Infinibranch:250ms 内 fork 整个 VM,是当前唯一把"VM fork"做成一等公民的产品 |
| Together Code Sandbox | 继承 CodeSandbox 那套低延迟内存解压(hibernate P95 511ms) |
| Replit Agent | Snapshot Engine 对 code+DB 做安全 try;用户拿独立 GCP project |
#C. 人类工程师用的 Cloud IDE / CDE
开源 / 自托管: Coder(Terraform 模板)、Sealos DevBox、kubernetes-sigs/agent-sandbox
SaaS: GitHub Codespaces、Replit、CodeSandbox、Gitpod Flex(搬到客户云)
浏览器内: StackBlitz WebContainer
#D. 底层 VMM / OCI runtime(提供"沙盒原料"的中游)
microVM: Firecracker、Cloud Hypervisor、libkrun、QEMU + KVM
VM-as-pod: Kata Containers
用户态内核: gVisor (runsc)
Unikernel: Nanos / OSv / Nabla Containers
基线: runc / Docker
#三、按编排方式分类(运维视角)
#自研 Fabric(不依赖 K8s)
┌──── E2B / Vercel Hive / CodeSandbox / Together ──── microVM 池 + 自家网关
│
├──── Modal ───── gVisor on serverless container fabric + 全球路由
│
├──── Cloudflare Sandbox SDK ── Durable Objects 给沙盒发 ID + 边缘 Container fabric
│
├──── Replit Goval ── 每 region 独立 Goval;用户独享 GCP project
│
├──── Morph Infinibranch ── 分布式 microVM runtime,原生支持 fork
│
├──── Runloop ── bare-metal hypervisor,VM + 容器双层
│
└──── Daytona ── NestJS 控制面 + 多 runner(runner 可装客户机房)
共同特点:因为多租 untrusted code 对 K8s 是噩梦(kubelet 信任 pod、cgroup 不够强、CVE 多), 这些厂干脆自己造 fabric。
#基于 K8s
Coder ── 多副本 coderd + 外部 Postgres + Workspace = K8s Pod / VM 模板
Sealos DevBox ── 标准 K8s + 自研控制面
kubernetes-sigs/agent-sandbox ── K8s CRD,把"agent runtime"做成 K8s 一等公民
Jupyter Enterprise Gateway ── Kernel = K8s pod
GitHub Codespaces ── VM 内的 dev container(不算严格 K8s,但思路接近)
但 gVisor 容器不是 Pod,绕过 Scheduler,Portal 自己当调度器
#浏览器内(无服务端)
StackBlitz WebContainer ── WASM 实现 Linux 内核仿真,跑在用户浏览器
#四、典型架构断面图(每家一张图)
下面用 ASCII 画几家最有代表性的架构。每张图聚焦"一次代码执行从用户到内核"的链路。
#4.1 E2B(最纯粹的 Firecracker microVM 路线)
SDK (Python/TS)
│
│ HTTPS
▼
┌─────────────────┐
│ E2B API │ — 申请 sandbox / 拿 URL
└────────┬────────┘
│
▼
┌─────────────────┐ Template snapshot
│ Sandbox Manager │←── (Dockerfile 构建后存成 microVM 镜像)
└────────┬────────┘
│ "起一个 VM"
▼
┌───────────────────────────────┐
│ EC2 host pool(裸 EC2,无 K8s)│
│ ┌───────────────────────────┐│
│ │ Firecracker MicroVM ││ ← <200ms boot from snapshot
│ │ ├─ Guest Linux kernel ││
│ │ └─ rootfs + 用户进程 ││
│ └───────────────────────────┘│
└───────────────────────────────┘
│
│ 端口转发 + 公网 URL
▼
外部访问 (LLM agent)
#4.2 Modal(gVisor + serverless fabric)
SDK (Python decorator)
│
▼
┌─────────────────┐
│ Modal Control │ — 把 @sandbox 函数注册成可调用单元
└────────┬────────┘
│
▼
┌─────────────────────────────────┐
│ Serverless container fabric │
│ ┌─────────────────────────────┐│
│ │ gVisor (runsc) container ││ ← sub-second cold start
│ │ ├─ rootfs (网络共享) ││ 按秒计费
│ │ └─ 用户进程 ││
│ └─────────────────────────────┘│
└─────────────────────────────────┘
│
▼
Modal 网关 → 公网
特点:跟普通 Modal Function 共用 fabric,价格是 Function 的 3 倍(Sandbox CPU $0.142/hr)。
#4.3 Cloudflare Sandbox SDK(边缘 + Durable Objects)
Worker 代码
│
│ env.SANDBOX.get(id) ← 用 Durable Object ID 寻址沙盒
▼
┌───────────────────────────────┐
│ Cloudflare 边缘节点(任一 PoP)│
│ ┌─────────────────────────┐ │
│ │ workerd (V8 isolate) │ │ ← Worker
│ └────────────┬────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────┐ │
│ │ Durable Object (Sandbox)│ │ ← 沙箱"邮箱地址"
│ │ └─→ Container │ │
│ │ ├─ Linux kernel │ │
│ │ └─ user code + fs │ │
│ └─────────────────────────┘ │
└───────────────────────────────┘
│
▼
访问者从最近的边缘 PoP 进来
特点:沙箱是有"地址"的对象(Durable Object ID),全球一致路由。这是别家没有的。
底层是完整 Linux Container(不是 microVM),通过 Workers Containers 跑在边缘节点上。 2026-04-22 GA,提供 PTY terminal / 持久 code interpreter / inotify 文件事件 / snapshot-based session recovery(~2s restore vs. ~30s 全新启动)/ 出站 Workers egress proxy。
#4.4 CodeSandbox / Together Code Sandbox(最深的 hibernate 工程)
SDK / Web IDE
│
▼
┌────────────────┐
│ Pitcher API │ — 协作 + 任务调度
└────────┬───────┘
│
▼
┌───────────────────────────────────────┐
│ microVM 集群(自研 fabric) │
│ │
│ Cold start (P95): 2.7s │
│ Hibernate restore (P95): 511ms │
│ VM Clone: <2s │
│ │
│ ┌──────────────────────────────────┐│
│ │ Firecracker MicroVM ││
│ │ memory balloon → 清 page cache ││
│ │ zstd compress → 8GiB→412MiB ││
│ │ 每月 hibernate ~250k 个 VM ││
│ │ (数据源:CSB 官方 blog 2024) ││
│ └──────────────────────────────────┘│
└───────────────────────────────────────┘
工程亮点:用 memory balloon 在 hibernate 前主动让 guest 把内存腾出来,再压缩。 这是"最巧"的工程之一,把通用 microVM hibernate 的延迟做到了 sub-second。
#4.5 Morph Infinibranch(VM fork 的极限)
Agent SDK
│
│ branch_from(snapshot_id)
▼
┌────────────────┐
│ Morph Cloud │ ← 每一步 setup 都被存成 snapshot
└────────┬───────┘
│
▼
┌───────────────────────────────────────┐
│ 分布式 Infinibranch Runtime │
│ │
│ T0 ──── Snapshot S0 ───┬───→ VM A │
│ ├───→ VM B │
│ └───→ VM C │
│ │
│ 每个 VM 都从 S0 fork,<250ms 启动 │
│ 完整保留进程内存 + 磁盘状态 │
└───────────────────────────────────────┘
适用场景:agent RL / test-time scaling——LLM 想试 5 种方案, fork 出 5 个一模一样的环境,分别跑,挑最优;这是其他厂做不到的。
底层 VMM 公开资料未细化(待核实,公开 blog 只描述能力不暴露引擎), Morph 自述为"分布式 microVM runtime";与 CodeSandbox 的 VM clone (<2s) 区别在于 fork 是跨节点而非单机内复制,本质上把"VM 当 git branch"做成 SDK 一等公民。
#4.6 GitHub Codespaces(VM 内的 dev container)
VS Code / Web IDE
│
│ wss://...
▼
┌────────────────────┐
│ Codespaces 控制面 │
└─────────┬──────────┘
│
▼
┌───────────────────────────────┐
│ Azure VM(每个 codespace 一台)│
│ ┌─────────────────────────┐ │
│ │ Docker (dev container) │ │ ← devcontainer.json 定义
│ │ ├─ rootfs │ │
│ │ └─ 用户工作区 (持久卷) │ │
│ └─────────────────────────┘ │
│ + Prebuild 容器快照 (加速) │
└───────────────────────────────┘
注意:这是人类用的 CDE,不是 agent 沙盒。每个 codespace 一台 VM, 启动慢但功能全。
#4.7 StackBlitz WebContainer(最反直觉的一个)
浏览器(用户的电脑)
│
│ JavaScript 运行
▼
┌─────────────────────────────────┐
│ 浏览器进程 │
│ ┌───────────────────────────┐ │
│ │ WebContainer wasm bundle │ │ ← Linux 内核仿真层
│ │ ├─ Node.js (wasm) │ │
│ │ ├─ npm / pnpm │ │
│ │ ├─ in-memory fs │ │
│ │ └─ Service Worker = 网卡 │ │
│ └───────────────────────────┘ │
└─────────────────────────────────┘
│
│ 没有!服务端是空的
▼
(无)
代价:不能跑原生二进制(只能 wasm + Node 生态);价值:0 服务器成本 + 隐私 100%。 适合教程、文档站、playground。
│
│ POST /sbv1/acquire
▼
┌──────────────────┐
│ sandbox-portal │ ← Hertz HTTP;排队 + 锁 + 状态机
└────┬─────────────┘
│ Kitex gRPC
▼
┌──────────────────────────────────────┐
│ K8s Cluster: sandbox-system │
│ │
│ Karpenter ←───── Portal Scaler │ ← 绕过 K8s Scheduler
│ │ │ 按容量直接拉 EC2
│ ▼ │
│ ┌──────────────────────────────┐ │
│ │ gVisor 节点 (DaemonSet) │ │
│ │ ┌────────────────────────┐ │ │
│ │ │ sandbox-agent (gRPC) │ │ │
│ │ └─┬──────────────────────┘ │ │
│ │ │ runsc create/restore │ │
│ │ ▼ │ │
│ │ ┌────────────────────────┐ │ │
│ │ │ gVisor (runsc) 容器 │ │ │
│ │ │ ├─ sentry (假内核) │ │ │
│ │ │ ├─ s6-overlay (init) │ │ │
│ │ │ ├─ :8080 health-checker│ │ │
│ │ │ ├─ :6080 noVNC │ │ │
│ │ │ ├─ :8889 shell-mcp │ │ │
│ │ │ ├─ :7999 playwright-mcp│ │ │
│ │ │ ├─ :8100 desktop-mcp │ │ │
│ │ │ └─ Chrome + Xvfb + VNC │ │ │
│ │ └────────────────────────┘ │ │
│ │ │ Cilium ENI IP │ │
│ │ ▼ btrfs CoW rootfs │ │
│ └──────────────────────────────┘ │
│ │
│ Headless Service sandbox-{id} │
│ ▲ CoreDNS A → sandbox_ip │
│ │ │
│ Caddy (reverse_proxy + host regex) │
│ ▲ HTTP 80 │
│ │ │
│ Istio Gateway (TLS 终止 + ACM) │
│ ▲ 443 │
└──────────────────────────────────────┘
│
▼
L1: 节点本地 btrfs ckpt(同节点 wake,~1.5s)
L2: S3 sandbox-checkpoints-{env}(跨节点兜底,~4-7s)
混搭的特点:
- 运行时:用 gVisor(不是 microVM 也不是 runc)—— 给 hibernate 足够好用 + 安全够强
- 快照:runsc checkpoint + 双层缓存(L1 本地 btrfs + L2 S3)
- 网络:Cilium ENI 直分 VPC IP + Headless Service + 通配符 Caddy 域名
- 调度:K8s 但绕过 Scheduler,Portal 自己驱动 Karpenter
- 应用栈:每个沙箱内置 Chrome + VNC + 多个 MCP server,直接给 Agent 用
把上面的所有维度合一张坐标图:
冷启动快
│
│
E2B ● │ ● Daytona
│ ● Vercel
│
│ ● Cloudflare Sandbox
微VM 路线 ────────────┼──────────────── 容器路线
│
│
CodeSandbox │ ● Codespaces
● │ ● Coder
Replit │ ● Sealos
● │
● │ Sandbox 直接给 Agent 内置浏览器/VNC
│
│ ● Modal (gVisor)
│
冷启动慢
│
支持长会话 / hibernate
|------|-------------|------------------| | 隔离技术 | Firecracker microVM 占主流 | gVisor + btrfs + Cilium 三件套 | | 启动速度 | E2B/Daytona 追求 sub-200ms | 冷启 5-8s,wake 1.5s(押注 wake 而非冷启) | | 沙箱内容 | "干净 Linux",让用户自装 | 预装 Chrome + VNC + 多个 MCP server,开箱即用 | | 网络入口 | 自家 SaaS 网关 | Caddy + 通配符域名,每个 port 独立子域名 | | 编排层 | 自研 fabric 多 | K8s + Karpenter,但绕开 Scheduler | | 持久化 | 自家 snapshot | L1 btrfs + L2 S3 双层 checkpoint | | 计费模型 | 按秒按 vCPU | Valkey 直扣 + Dapr PubSub 异步对账 |
所以才会内置浏览器 + VNC + MCP,外人看是过度设计,但对 Agent 平台是刚需。
#六、行业演化趋势
按公开资料看,2024-2026 年这个赛道在五个方向同时演化:
#6.1 大厂从容器迁到 microVM
- Replit:2025 年公开承认正在把 Conman 容器替换成 microVM(无共享内核)
- Cloudflare:Workers 之上加 Containers(2025)→ Sandbox SDK GA(2026-04)
- Vercel:2025 年 1 月发布 Hive(自家 Firecracker fabric),2026-01 Sandbox GA
驱动力:多租 untrusted code 的容器逃逸 CVE 太多,VM 隔离是行业共识答案。
#6.2 hibernate / snapshot 成为一等公民
不是新功能了,是 必备。
| 厂商 | snapshot 工程亮点 |
|---|---|
| CodeSandbox / Together TCI(同套底座) | memory balloon + zstd,8GiB → 412MiB,hibernate P95 511ms |
| Morph | Infinibranch:分布式 runtime,250ms 内 fork 整个 VM |
| Replit | Snapshot Engine:code + DB 同时 snapshot,给 agent 安全 try |
| Daytona | Stateful snapshot 是产品级第一卖点 |
#6.3 "VM fork" 在变成 agent 原语
agent 想"试 5 种方案选最好的",你怎么给它 5 个一模一样的环境?
- Morph Infinibranch:原生支持 fork
- CodeSandbox VM clone:< 2s
- Replit Snapshot Engine:从 fork 出的快照独立改
"把 hibernated 沙箱的 checkpoint 当模板再 restore 一份新沙箱",效果接近但代价比 Morph 高 (因为要走完整 wake 流程)。
#6.4 计费收敛到 active CPU
- Cloudflare(2026-04 Sandbox GA):active CPU $0.00002/vCPU-sec + $0.0000025/GB-sec memory,请求到达才开始扣,scale-to-zero
- Vercel:active CPU $0.128/vCPU-hr + Provisioned Memory $0.0212/GB-hr(1 min minimum);I/O 等待不计
- E2B / Modal / Daytona:一直按秒(vCPU + RAM 各自计)
- Together TCI:按 session $0.03 / 60 min(少数派)
因为 agent 工作流大量 idle 等 LLM 回复,按"占着资源就计费"会让 user 心态爆炸。
#6.5 K8s vs 自研 fabric 的分裂
把 sandbox 当 K8s pod 管的有 Coder、Sealos、Jupyter EG, 不当 K8s 管的有 E2B、Modal、Vercel、Cloudflare、CodeSandbox、Replit、Morph、Runloop、Daytona。
本质上是承认"K8s 调度对 agent sandbox 不够细粒度",但又想要 K8s 的 Service / Karpenter 等周边。
代表性的反思:Gitpod 在 2024-11 公开宣布抛弃 K8s 架构(CEO 文章标题就是"discontinues journey of experiments, failures and dead ends with kubernetes"), 全新 Flex 架构改为客户云上 VM + 容器。
#七、数据出处
主要参考链接(按章节出现顺序排):
Tier 1 SaaS
- E2B:https://e2b.dev/blog/firecracker-vs-qemu / https://e2b.dev/pricing
- Daytona:https://www.daytona.io/docs/en/architecture/ / https://www.daytona.io/pricing
- Modal:https://modal.com/blog/speeding-up-container-launches / https://modal.com/pricing
- Runloop:https://docs.runloop.ai/docs/devboxes/overview / https://www.prnewswire.com/news-releases/runloop-unveils-enterprise-grade-sandboxes-for-ai-coding-agents-302460834.html
- Morph:https://www.morph.so/blog/infinibranch/ / https://cloud.morph.so/docs/documentation/snapshots
- Cloudflare Sandbox SDK:https://developers.cloudflare.com/sandbox/concepts/architecture/ / https://blog.cloudflare.com/cloudflare-containers-coming-2025/
- Vercel Sandbox:https://vercel.com/docs/vercel-sandbox / https://vercel.com/blog/vercel-sandbox-is-now-generally-available
- Together:https://www.together.ai/blog/code-sandbox-code-interpreter / https://www.together.ai/code-interpreter
Tier 2 IDE/CDE
- Replit:https://blog.replit.com/inside-replits-snapshot-engine / https://blog.replit.com/regional-goval
- Codespaces:https://docs.github.com/en/codespaces/about-codespaces/deep-dive
- StackBlitz:https://webcontainers.io/ / https://blog.stackblitz.com/posts/introducing-webcontainers/
- CodeSandbox:https://codesandbox.io/blog/how-we-scale-our-microvm-infrastructure-using-low-latency-memory-decompression / https://codesandbox.io/blog/how-we-clone-a-running-vm-in-2-seconds
- Coder:https://coder.com/docs/admin/infrastructure/architecture
- Gitpod Flex / Ona:https://ona.com/stories/naming-is-hard / https://devclass.com/2024/11/06/gitpod-discontinues-journey-of-experiments-failures-and-dead-ends-with-kubernetes/
Tier 3 底层
- Firecracker:https://github.com/firecracker-microvm/firecracker / https://aws.amazon.com/blogs/opensource/firecracker-open-source-secure-fast-microvm-serverless/
- gVisor:https://gvisor.dev/docs/architecture_guide/intro/ / https://github.com/google/gvisor
- Kata:https://katacontainers.io/ / https://github.com/kata-containers/kata-containers/blob/main/docs/design/architecture/README.md
- Cloud Hypervisor:https://github.com/cloud-hypervisor/cloud-hypervisor
- Nanos / Nabla:https://nanos.org/ / https://nabla-containers.github.io/
Tier 4 OSS
- Sealos:https://github.com/labring/sealos / https://sealos.io/blog/what-is-devbox/
- microsandbox:https://github.com/zerocore-ai/microsandbox
- k8s-sigs/agent-sandbox:https://github.com/kubernetes-sigs/agent-sandbox / https://www.infoq.com/news/2025/12/agent-sandbox-kubernetes/
- Riza:https://riza.io / https://riza.io/blog/riza-raises-2-7M-to-run-ai-generated-code
资料覆盖时间窗:2024-01 至 2026-04。在线资料请以官方文档为准(产品迭代很快)。