怎么安全地跑 agent 生成的代码?
verifier 为什么要放在 sandbox 外面?

英文问法How do you safely run code that an agent wrote? · What is gVisor? How is a microVM different from a container? · Why must the verifier live outside the sandbox?

考过Unity 自己的材料:FlashVector Figure 2 的图中文字 "fixed verifier the agent cannot edit · all candidates run sandboxed",这句只出现在论文的图里,正文没有展开 · JD:NVIDIA Agentic AI Kernel Generation "integrate agents with compilers, profilers, execution sandboxes, and runtimes"(JR2016992)、Etched "execution environments where agents can verify their own work"(Ashby) · 别家面经原题:科大讯飞 AI 应用一面(校招,面试 2026-09-15)「Runtime 的沙箱与隔离机制如何做,gVisor 是什么?」「microVM 是什么,与普通 VM、Docker 的区别以及隔离强度如何理解?」(牛客)、字节后端(Agent 方向)实习一面(发帖 2026-04-08)「如果要实现一个代码执行沙箱,你从后端角度如何限制 CPU、内存和网络访问?」(牛客) · 中文面经样本里有 11 帖问到 sandbox · 没有 Unity 自己的面经原题

先弄清楚:每个概念是什么

Sandbox
一个受限的执行环境,候选代码只能在里面跑,出了事不波及外面。
Container
和宿主共享同一个 kernel 的一组进程。namespace 管它看得见什么,cgroups 管它能用多少 CPU 和 memory。
gVisor
跑在 user space 的一层 kernel。候选代码的 system call(syscall)先被它拦下来处理,不直接交给宿主 kernel。
MicroVM
用硬件虚拟化起的轻量 VM,有自己的 guest kernel。例:Firecracker 用 KVM 创建 microVM。
Verifier
判定候选代码对不对、快不快的固定代码。agent 改不了它。

看图:谁在 sandbox 里,谁在外面

agent 只提案 patch sandbox:每份候选代码一个 候选代码 CPU、memory、时间有上限 默认断网 只有 workspace 可写 每次从同一个 image 启动 verifier benchmark 脚本 在 sandbox 外,只读 agent 改不了 输出 调用、计时 keep / reject:verifier 决定,agent 只收到结果
图 1:候选代码在 sandbox 里跑。verifier 和 benchmark 脚本在外面,对 agent 只读,keep 还是 reject 由它们定。

30 秒回答

Agent-written code is untrusted. Each candidate gets its own container or microVM, started from the same clean image, with CPU, memory and time limits, no network, and write access only to its workspace. The verifier and the benchmark scripts sit outside that boundary and are read-only, so the agent only proposes and can't edit what judges it. On GPUs, compilation can go to CPU nodes, but a timed run gets a whole device, for safety and clean timing. A container shares the host kernel; gVisor or a microVM isolates more strongly.

三种隔离技术

syscall 到哪里隔离强度
Container直接到宿主 kernel最弱
gVisor先到 user space 的那层 kernel居中
MicroVM到自己的 guest kernel最强

FlashVector 没写 sandbox 用哪一种。能看到的只有 GPU kernel 在 local simulated environment 里跑,config sweep 在生产机型的隔离节点上跑。自己团队的 agent 写的 kernel,我会先用 container 加资源上限。要跑别的租户的代码时,再换 gVisor 或 microVM。

Sandbox 要管住什么

管什么做法
CPU 和 memorycgroups 设上限
时间timeout,到点由外面的进程 kill
网络默认断网,给 sandbox 一个不通外网的 network namespace
文件只有 workspace 可写;verifier 和 benchmark 脚本只读
状态每份候选代码从同一个 image 启动,不留上一份的状态
GPU测量时独占一张卡;编译放 CPU 节点

GPU 这一行是 CUDA Agent 的做法。它有 128 张 H20 的 sandbox pool,verify 和 profile 脚本用文件权限保护。独占一张卡也是为了计时干净(见 kernel benchmark)。agent 钻评测漏洞的例子见 reward hacking。

必答点

追问

让 agent 自己写 test 行不行?

不行,判定要由 sandbox 外的 verifier 做(见 kernel 正确性)。

microVM 和普通 VM 有什么区别?

microVM 只模拟很少的设备,所以启动快、开销小。Firecracker 官网写它只有 5 个模拟设备,启动时间低于 125 ms,每个 microVM 的 memory 开销低于 5 MiB。

来源FlashVector Figure 2、§4.2 Profile、§5.4.2 · CUDA Agent(GPU sandbox pool、CPU 编译和 GPU 测量分离) · KernelFalcon · gVisor 文档 · Firecracker 官网 · 面经原帖:科大讯飞、字节 · ml-八股 08 第 27 题 · 同类系统对照表