Sandboxing Agent-Generated Code on Serverless GPU

Connor Blier
Founding GTM

A rectangular document or code file, its top portion showing lines of text like code, transitioning at the bottom into a stylised open box or sandbox tray shape, suggesting code being contained and run inside an isolated enclosure.

Sandboxing Agent-Generated Code on Serverless GPU

Sandboxing agent-generated code on a serverless GPU means layering two separate boundaries: a compute boundary (gVisor syscall interception or a Firecracker-style microVM) that isolates the runtime, and an authority boundary (RBAC, LOGOS-1, fresh authorization checks) that limits what the code is allowed to do - because on a GPU the device is passed through and the driver is shared.

Almost every published guide to sandboxing agent-generated code is, if you read it closely, a CPU guide. It reaches for a Firecracker-style microVM by default, treats cold-start latency as the only tradeoff worth discussing, and stops there. That advice is fine until the code your agent writes needs to touch a GPU - at which point the assumptions underneath it quietly stop holding.

This guide is about containing code written by agents that must run on an accelerator - not about serving inference to agents. If you are a Lead ML Engineer standing up a serverless GPU environment where an LLM proposes and then executes arbitrary Python, you need a framework that treats the compute boundary and the authority boundary as two different problems. They are.

Why the standard agent-sandbox advice is a CPU answer

The canonical answer to "how do I run untrusted, agent-generated code?" is a microVM. Firecracker is the reference implementation because it does exactly what the serverless world wants: it combines "the security and workload isolation properties of traditional VMs with the speed, agility and resource efficiency enabled by containers," and it can "safely run workloads from different customers on the same machine." For CPU-bound code that is close to a complete answer.

The reason it feels complete is that a CPU workload lives entirely inside the guest. The kernel is virtual, the devices are virtual, and the only real cost of adding isolation is the milliseconds it takes to boot. So the entire debate collapses into cold-start time - which is why every CPU sandbox guide reads like a cold-start guide.

What actually changes when the sandboxed code needs a GPU

The device is passed through, not virtualized

A GPU is not a virtual device the hypervisor can fabricate. To let sandboxed code run CUDA, the physical accelerator (or a partition of it) is passed through into the guest. That passthrough is the thing that makes the workload useful, and it is also the thing that punches a hole in the neat "everything is virtual inside the guest" model the CPU answer relied on.

The driver is shared with the host

Once the device is passed through, the guest is talking to a driver stack that shares state with the host. The isolation boundary that a microVM draws so cleanly around CPU and memory becomes porous at exactly the point the GPU enters. Your threat model has to account for a driver surface that both the tenant and the host touch - a consideration that simply does not exist for pure-CPU sandboxing.

Isolation has a measurable cold-start price

On CPU, cold-start is an annoyance. On GPU, it is the dominant cost, because you are not just booting a guest - you are initializing CUDA context, loading multi-gigabyte weights, and warming the driver. The isolation choice you make sits directly on that critical path. In Cerebrium's own snapshotting work, we measured a 71% average cold-start reduction across a six-workload benchmark suite, with reductions as high as 88% on vLLM - evidence of how much runtime state a GPU sandbox has to reconstruct before it can do anything. The isolation layer either helps you snapshot that state or fights you on it.

gVisor - intercepting the syscalls instead of handing over the kernel

The userspace-kernel model

gVisor takes a different tack from a microVM. Per its docs, "gVisor intercepts application system calls and acts as the guest kernel, without the need for translation through virtualized hardware. gVisor may be thought of as either a merged guest kernel and VMM, or as seccomp on steroids." There is no full virtual machine - there is a userspace kernel standing between the workload and the host.

Cold-start behavior

Because there is no guest kernel to boot and no fixed block of guest physical memory to stand up, gVisor gives you "a flexible resource footprint (i.e. one based on threads and memory mappings, not fixed guest physical resources) while also lowering the fixed costs of virtualization." For a GPU sandbox that spins up per request, a lower fixed cost of isolation is exactly what you want on the critical path.

The tradeoff

gVisor is explicit that the model "comes at the price of reduced application compatibility and higher per-system call overhead." For GPU workloads that is not a footnote: CUDA is syscall- and ioctl-heavy, so "higher per-system call overhead" and "reduced application compatibility" can bite precisely where your accelerator code lives. You buy a lighter isolation boundary and pay for it in compatibility risk.

Firecracker microVMs - VM-grade isolation at container speed, and the GPU wall

Why microVMs became the serverless default

Firecracker earned its default status on numbers. With "a minimal Linux kernel, single-core CPU, and 128 MiB of RAM, Firecracker supports a steady mutation rate of 5 microVMs per host core per second" - 180 microVMs per second on a 36-core host. That density plus true VM isolation is why serverless CPU platforms standardized on it.

Where it breaks for GPU

The microVM's strength is a hard boundary around virtualized hardware. A GPU is not virtualized hardware - it is passed through, and the driver is shared with the host. So the very property that makes Firecracker attractive on CPU is the property that a GPU passthrough compromises. You keep the boot-speed benefits, but the clean isolation story develops an asterisk at the device.

Cold-start vs gVisor

A microVM's fixed footprint (guest kernel, fixed guest memory) is the cost gVisor was designed to avoid. For a serverless GPU function that scales to zero and back, that fixed cost recurs on every cold start. gVisor's thread-and-mapping footprint can win here - at the compatibility cost above. This is the central compute-boundary tradeoff.

Choosing the compute boundary for serverless GPU

There is no single right answer; there is a decision. Choose a microVM when tenant separation is your hardest requirement and you can absorb the fixed cold-start footprint - and lean on snapshotting to claw it back. Choose gVisor when per-request startup dominates your economics and your CUDA workload stays inside its compatibility envelope. Either way, cold-start is engineering, not fate: we cut machine boot time by 83% by reworking node startup on AWS, detailed in our custom-container-image work, and Cerebrium's serverless GPU cold starts land in the 2-4 second range. The broader platform tradeoffs are covered in our guide to choosing a serverless GPU platform and in GPU inference for AI agent workloads.

The compute boundary is not the authority boundary

Here is the mistake even careful teams make: they pick an isolation runtime and call the problem solved. But a perfectly sandboxed process that still holds a valid database credential can do enormous damage without ever escaping its sandbox. The compute boundary limits where code runs. The authority boundary limits what it is allowed to do. You need both.

RBAC and capability boundaries

Start by constraining capabilities regardless of code content. As one practitioner framing puts it, "since everything can be capability constrained using RBAC," you can scope agent-generated endpoints so one role has read access to all databases while another has full CRUD and a third has only read-write on a single database. The sandbox never has to reason about the code - the capability grant already bounds the blast radius.

LOGOS-1 runtime authority

The deeper principle is separating cognition from execution. The LOGOS-1 proposal states it directly: "Capability != Authority, AdaptiveState != Authority, Proposal != Execution... the language model remains the cognitive component: it can reason, retrieve memory, learn procedures, evaluate evidence, and propose actions. But execution authority is deliberately kept outside adaptive model state." For GPU sandboxing this means the model that writes the CUDA code is never the component that authorizes it to run against real resources.

Authorization revalidation timing

The last gap is time. An agent workflow can pause between approval and execution, and "if the current source of truth for authorization can change after approval but before actual execution," you have a race: authority valid, action proposed, call approved, permission revoked, run resumes, execution begins against a grant that no longer exists. The fix is a fresh authorization check at execution time, or strict approval-to-execution atomicity. On serverless GPU this matters more, not less, because scale-to-zero naturally inserts a gap between approval and the cold-started execution.

Putting it together - a reference decision for containing GPU-bound agent code

Layer the two boundaries deliberately. First, pick a compute boundary: microVM for maximum tenant isolation, gVisor when per-request cold-start economics dominate and your CUDA path tolerates the syscall overhead - and treat GPU passthrough plus the shared driver as an explicit part of your threat model either way. Second, wrap that runtime in an authority boundary: RBAC-scoped capabilities so the code can only touch what its role permits, a LOGOS-1-style split so the proposing model never carries execution authority, and a fresh authorization revalidation at the moment of execution to close the approval-to-execution race. Third, make cold-start an engineering target rather than an accepted cost, using snapshotting to reconstruct CUDA state fast. Get all three right and you have contained agent-generated GPU code without paying for isolation you did not need or trusting a boundary that a passed-through device quietly breaks.

For related depth, see our work on serverless GPU cold starts and the Cerebrium run execution model, which runs your code in the cloud within ~2 seconds. If you are still evaluating where to run any of this, our overview of the serverless platform landscape and how to choose a serverless provider cover the surrounding decisions, and prefix caching for multi-turn LLM agents goes deeper on keeping agent state warm across turns.

Frequently asked questions

Is a Firecracker microVM the right default for sandboxing GPU-bound agent code?
Not automatically. Firecracker's isolation is built around virtualized hardware, but a GPU is passed through rather than virtualized and its driver is shared with the host, so the clean microVM boundary develops an exception at exactly the device you care about. It remains a strong choice when tenant separation is your hardest requirement, provided you manage the fixed cold-start footprint.
When should I pick gVisor over a microVM?
Choose gVisor when per-request startup cost dominates your economics and your CUDA workload stays inside its compatibility envelope. gVisor intercepts syscalls and acts as a userspace guest kernel, giving a flexible resource footprint and lower fixed virtualization cost - but at the price of reduced application compatibility and higher per-system-call overhead, which can matter for syscall-heavy GPU code.
Why isn't the sandbox enough on its own?
A sandbox limits where code runs, not what it is allowed to do. A perfectly isolated process still holding a live database credential can cause damage without escaping. You need a separate authority boundary - RBAC-scoped capabilities, a cognition-versus-execution split like LOGOS-1, and fresh authorization checks at execution time.
What is the authorization revalidation race, and why does serverless GPU make it worse?
It is the gap where authorization is revoked after a tool call is approved but before it executes. Serverless GPU scale-to-zero naturally inserts a delay between approval and cold-started execution, widening that window. Revalidate authorization fresh at execution time, or enforce approval-to-execution atomicity.
How much does isolation actually cost in cold-start time on GPU?
Enough that it belongs on the critical path. GPU cold start means CUDA context init, multi-gigabyte weight loads, and driver warmup. In our snapshotting benchmarks we measured a 71% average cold-start reduction, up to 88% on vLLM, showing how much runtime state a GPU sandbox must reconstruct before serving traffic.

Get started with Cerebrium

Deploy AI models on serverless GPUs in minutes, with no infrastructure to manage. Start for free and pay only for the compute you use.

Sign up free

Sources

  1. gvisor.dev
    “gVisor intercepts application system calls and acts as the guest kernel, without the need for translation through virtualized hardware. gVisor may be thought of as either a merged guest kernel and VMM, or as seccomp on steroids.”

    Defines gVisor's userspace-kernel isolation model versus microVMs.

  2. gvisor.dev
    “This architecture allows it to provide a flexible resource footprint (i.e. one based on threads and memory mappings, not fixed guest physical resources) while also lowering the fixed costs of virtualization. However, this comes at the price of reduced application compatibility and higher per-system call overhead.”

    gVisor's cold-start advantage and its compatibility/overhead tradeoff.

  3. github.com
    “Firecracker microVMs combine the security and workload isolation properties of traditional VMs with the speed, agility and resource efficiency enabled by containers. They provide a secure, trusted environment for multi-tenant services, while maintaining minimal overhead.”

    Why microVMs became the serverless default for untrusted code.

  4. github.com
    “With a microVM configured with a minimal Linux kernel, single-core CPU, and 128 MiB of RAM, Firecracker supports a steady mutation rate of 5 microVMs per host core per second (e.g., one can create 180 microVMs per second on a host with 36 physical cores).”

    Firecracker's startup density numbers.

  5. github.com
    “Firecracker can safely run workloads from different customers on the same machine.”

    Multi-tenant isolation property of microVMs.

  6. discuss.huggingface.co
    “Since everything can be capability constrained using RBAC, you can generate endpoints such as: 1. The CEO have read access to all databases 2. The CTO have full CRUD towards all databases 3. The CMO has only read, write, and update access to marketing database”

    RBAC/capability constraints as the authority boundary for agent-generated code.

  7. community.openai.com
    “Capability != Authority, AdaptiveState != Authority, Proposal != Execution. In LOGOS-1, the language model remains the cognitive component: it can reason, retrieve memory, learn procedures, evaluate evidence, and propose actions. But execution authority is deliberately kept outside adaptive model state.”

    Separating agent cognition from execution authority at runtime.

  8. community.openai.com
    “If the current source of truth for authorization can change after approval but before actual execution, where would you perform the final fresh authorization check?”

    The need for a fresh authorization check at execution time.

  9. community.openai.com
    “authority valid → agent proposes a consequential tool action → tool call is approved → authoritative permission changes or is revoked → run resumes → tool execution begins”

    The authorization revocation race condition in resumable agent workflows.

  10. cerebrium.ai
    “Across the benchmark suite, Cerebrium snapshots reduced cold starts by an average of 71% compared to running the same workloads on Cerebrium without snapshots, with reductions as high as 88% on vLLM.”

    First-hand GPU cold-start reduction from snapshotting.

  11. cerebrium.ai
    “In this post, we show how we reworked node startup and initialization on AWS to reduce machine boot time by 83%, cut the long tail of cold starts, and lower the amount of excess capacity we needed to keep running, improving overall utilization.”

    First-hand 83% machine boot time reduction.

  12. cerebrium.ai
    “**Serverless CPU/GPU Inference**: With cold start times of 2-4 seconds, its the most performant serverless platform on the market.”

    First-hand 2-4 second cold-start figure.

  13. cerebrium.ai
    “Within ~2 seconds, your code runs in the cloud, and you'll see real-time logs streamed back to your CLI.”

    First-hand ~2 second cloud execution latency for cerebrium run.


Related resources

See all
A gear-shaped dial made of a toothed ring encircling a percent-like question sign, evoking a switchable settings knob for gradually shifting traffic and reverting it, drawn as a single black icon.
Canary Rollout & Rollback on Serverless GPU Endpoints
A hexagonal crystal-lattice diagram: an outer hexagon frame encloses six small nodes arranged around a larger central node, all connected by straight lines like a network or circuit, suggesting several distinct components joined into one structure.
The Active-Parameter Lie: What a Mixture-of-Experts Model Actually Costs on a Serverless GPU
A stopwatch clock face rendered as a settings gear, symbolising automatically timed, self-managing training runs.
Serverless Training for LLMs: What It Actually Means (and Where It Breaks Down)