TL;DR: For multi-tenant, untrusted, model-written Python that needs real libraries: a microVM per session (Firecracker or Kata) where the platform supports it, or gVisor where microVMs are impractical, with no credentials inside, deny-by-default egress, a scratch filesystem and hard resource limits. Plain containers are acceptable only for single-tenant or trusted inputs, because every container shares the host kernel. Wasm is excellent for narrow, high-volume functions but usually cannot run arbitrary Python with native packages. Justify the choice by threat, compatibility and start-up cost.
How to approach it
Ask three things before choosing: whose code shares a host (one customer or many), what the code needs (numpy and pandas, system packages, network), and the volume and latency targets. Then compare the four on boundary strength, compatibility, start time and operations, and pick.
A strong answer
The threat. Model-written code is shaped by user uploads and anything else the model read, so treat it as hostile. With many tenants on one host, an escape reaches other customers' data, so the boundary must hold against kernel-level escapes.
The comparison.
| Container | gVisor | MicroVM | Wasm | |
|---|---|---|---|---|
| Shares host kernel | Yes | Mostly no (user-space kernel) | No (own kernel) | No (runtime) |
| Runs arbitrary Python with native packages | Yes | Mostly | Yes | Rarely |
| Start time | Fast | Fast | Sub-second to seconds | Very fast |
| Operational effort | Low | Moderate | Higher (virtualisation hosts) | Moderate |
| Fits | Trusted or single-tenant | Multi-tenant, containers' tooling | Multi-tenant, strongest general option | Narrow functions |
The pick. A microVM per session for a multi-tenant code interpreter running pandas on user files: own kernel, full compatibility, start times hidden by a warm pool. If the platform cannot run microVMs (no nested virtualisation, a managed container service), gVisor is the pragmatic alternative.
The controls that apply whatever you pick.
- No credentials inside; external access through a broker.
- Egress denied by default; a package mirror allowed if installs are needed.
- A scratch filesystem; uploads copied in, nothing mounted from the host.
- Limits on CPU time, memory, processes, disk and wall-clock, enforced by the runtime.
- One sandbox per session, destroyed afterwards; never reused across tenants.
- Instance metadata endpoints blocked.
How you would check it. A test suite of hostile snippets (fork bombs, memory exhaustion, attempts to reach the network or metadata, reads outside the workspace) run against every sandbox image in CI, expecting each to fail safely.
What interviewers probe next
"MicroVMs add start-up time." Firecracker-class microVMs boot in well under a second; the real start cost is workspace and dependencies, solved with snapshots and warm pools.
"Could you use containers with a strict seccomp profile?" That narrows the syscall surface and is a fine extra layer, but the kernel is still shared. For many tenants on one host, it is not the boundary to rely on.
"Where does Wasm fit?" High-volume, short computations with a fixed library set (formula evaluation, data transforms) where its start speed and capability model shine.
What if?
What if · interview follow-ups
Hold your answer as the constraints change
You chose a microVM per session for a multi-tenant code interpreter.
Start here
What if a customer needs the code to call their internal API?
Where do credentials and egress live?
Add an egress rule for that host through the broker, which attaches the customer's credential outside the sandbox and only for that session. The sandbox still holds no secret.
Carry it forwardNew access goes through the broker, not into the sandbox.
Weak answerPassing the API key into the environment.
Constraint changes
What if one customer's jobs need GPUs?
Does the boundary change?
GPU passthrough into microVMs is possible but complex; many platforms use dedicated hosts per tenant for GPU work instead, keeping the isolation guarantee by not sharing the machine.
Carry it forwardIf sharing is hard to secure, do not share.
Weak answerDropping to containers on shared GPU hosts.
Constraint changes
What if a hostile-snippet test starts passing (the snippet escapes)?
What is the response?
Treat it as a security incident: stop rolling out that image, patch, and check whether production sandboxes ran the vulnerable version. The test suite exists to catch exactly this before customers do.
Carry it forwardSandbox tests are security tests.
Weak answerMarking the test as flaky.
Now defend it
One-line choice?
A microVM per session (gVisor where microVMs are impractical) for multi-tenant untrusted Python, with no credentials inside, deny-by-default egress, a scratch filesystem, hard limits and hostile-snippet tests.
How it's scored
Weak: "Docker is a sandbox."
Hire: Recognises the shared-kernel risk and picks gVisor or a microVM for multi-tenant code.
Strong Hire: Starts from threat, tenancy and compatibility; compares all four on boundary, compatibility, start time and operations; picks with justification and a fallback; lists the controls that apply regardless; and proves them with hostile-snippet tests in CI.
Common mistakes
- Treating the model as a trusted author.
- Reusing sandboxes across sessions or tenants.
- Credentials in environment variables "because the code needs them".
- Choosing Wasm without checking that the needed packages run.