Resources / Code execution
Sandboxing for AI code: containers, gVisor, microVMs and WebAssembly compared
The main ways to sandbox AI-generated code — containers, user-space kernels, microVMs, WebAssembly and V8 isolates — and how to pick one.
A sandbox lets code run while limiting what it can touch: the file system, the network, other processes, other users' data, the host itself. For AI-generated code — which you haven't read and which an attacker may have influenced through prompt injection — the sandbox is the part that has to hold even when the code is wrong.
The options
### Containers (Docker, containerd)
Processes isolated with Linux namespaces and cgroups, sharing the host kernel.
- Strengths: familiar, fast to start, huge ecosystem, any language.
- Weaknesses: one kernel shared by everything — a kernel vulnerability can break out. Treat plain containers as a packaging tool, not a security boundary, for hostile code.
- Harden with: a non-root user, a read-only file system, dropped capabilities, seccomp profiles, no Docker socket, CPU and memory limits.
### User-space kernels (gVisor)
A kernel implemented in user space intercepts the program's system calls, so the code never talks to the host kernel directly.
- Strengths: much smaller attack surface than plain containers; still container-shaped.
- Weaknesses: some syscalls are slower or unsupported; I/O-heavy workloads pay a price.
### MicroVMs (Firecracker, Cloud Hypervisor, Kata Containers)
Each workload gets its own lightweight virtual machine with its own kernel, booting in a fraction of a second.
- Strengths: hardware-level isolation, the strongest common option for multi-tenant code.
- Weaknesses: more to operate; startup and memory overhead higher than containers.
### WebAssembly (Wasmtime, WasmEdge)
Code compiled to WebAssembly runs in a memory-safe runtime that can only use the capabilities you hand it (WASI).
- Strengths: starts in microseconds, deny-by-default capabilities, tiny footprint.
- Weaknesses: language and library support is narrower — great for some code, awkward for arbitrary Python with native packages.
### Language isolates (V8 isolates)
Many JavaScript contexts in one process, each with its own heap.
- Strengths: extremely fast and dense.
- Weaknesses: JavaScript/Wasm only; the isolation boundary is the engine, so it's usually paired with process-level defences.
How to choose
| If you need… | Consider |
|---|---|
| Hostile multi-tenant code, any language | MicroVMs |
| Stronger containers without changing tooling | gVisor |
| Millisecond starts, deny-by-default | WebAssembly or isolates |
| Trusted internal code | Hardened containers |
The sandbox is only one layer
Whatever runs the code, also add:
- Limits: timeouts, memory, output size, number of processes.
- Network egress rules: deny by default; allow-list the APIs the code needs.
- Secrets at run time only, never in the code or the prompt.
- Per-tenant identity: each workload can reach only its own data.
- Logging of what ran, what it called and what it returned.
On Wisp
Wisp gives every project its own isolated runtime and identity: a project's functions can reach only that project's storage, secrets and settings, run with fixed time and memory caps, and never see the model or Wisp's own credentials. You describe the code; the sandboxing, limits and scaling are already there. More on the security page.
Build it with Wisp — describe an API, get it live.