Skip to content

Interview question · Cloud, Container & AI Infrastructure Security

Design a sandbox for agent-generated code, including filesystem, network egress and GPU constraints.

Assume the code is hostile and design until that stops mattering. Then the interviewer adds a GPU and the internet, and you design again.

hardEssentialNewPreparation tags: Anthropic, OpenAI, GoogleUpdated Nov 2026

TL;DR: Use a per-session microVM or gVisor sandbox, hardened (non-root, read-only base, no runtime socket, no host mounts). Put nothing valuable inside: no credentials, only the task's files copied in read-only with an ephemeral scratch area. Deny network by default; allow only an internal package mirror through an egress proxy that rejects private and metadata addresses. Enforce CPU, memory, disk, process and wall-clock limits. For GPUs, give each session a dedicated device or a partition with documented isolation, and clear memory between uses. Destroy the sandbox after the session, broker any needed service calls outside it with scoped tokens, and treat all outputs as untrusted.

How to approach it

State the threat: the code may be written under the influence of injected content, so assume it is hostile. Separate the design into isolation boundary, environment (files, credentials, network, resources), lifecycle, outputs and observability. Expect the interviewer to change constraints; show how each change is absorbed.

A strong answer

FIG · SANDBOX FOR AGENT-GENERATED CODE · NOTHING VALUABLE INSIDE
Per-session isolation, deny-by-default egress, bounded resources
  1. 1

    1 · Per-session microVM or gVisor

    Hardened

    • Non-root, read-only base, no runtime socket, no host mounts
  2. 2

    2 · No secrets inside

    Task files only

    • Inputs copied read-only, ephemeral scratch
  3. 3

    3 · Network denied by default

    Internal package mirror only

    • No metadata endpoint, no internet
  4. 4

    4 · Resource limits

    CPU, memory, time, GPU

    • Dedicated GPU or MIG slice; no shared memory
  5. 5

    5 · Destroyed after

    Nothing persists

    • Outputs reviewed before leaving

Threat model. Hostile code tries to escape to the host, read secrets, reach internal services or the metadata endpoint, exfiltrate the user's files, persist for later sessions, attack other tenants via shared hardware, or exhaust resources.

Design.

ConcernDecision
BoundaryFirecracker or Kata microVM per session (or gVisor where startup latency matters more); hardened config
FilesCopy in only task inputs; mount read-only; ephemeral scratch disk with a size cap; nothing from the host
CredentialsNone. If code must call a service, a broker outside the sandbox makes the call as the user with a scoped, short-lived token
NetworkNo egress by default; optional allowlisted package mirror via proxy that blocks private ranges and metadata
ResourcesvCPU, memory, disk, PID and wall-clock limits; kill on breach
GPUDedicated GPU per session, or hardware partitioning with documented isolation; driver patched; memory cleared on release
LifecycleFresh sandbox per session, destroyed afterwards; pre-warmed pool of never-used sandboxes for latency
OutputsSize- and type-limited; rendered safely; never executed on the host; scanned if passed onward
ObservabilityLog code, network attempts, resource usage and exit reasons per session

Constraint changes.

  • "It needs the internet to call public APIs." Route through an egress proxy with domain allowlists per feature, strip credentials, log destinations, and cap request rates; open internet becomes an exfiltration channel otherwise.
  • "It needs the user's database." No credentials inside; a query broker outside authenticates as the user, enforces read-only access and row limits.
  • "It needs to persist state across sessions." Store state outside the sandbox in a per-user location, treated as untrusted when loaded back in.
  • "Latency must be under a second." Pre-warmed fresh microVMs or gVisor; never reuse a previous session's sandbox.

GPU specifics. GPU drivers are large kernel components, and GPU memory isolation has had weaknesses (LeftoverLocals, CVE-2023-4969). For untrusted code, avoid sharing a GPU between tenants or sessions without hardware partitioning that the vendor documents as isolating, clear memory between uses, and keep drivers patched.

FIG · BYPASSED VS PROTECTED · AGENT CODE SANDBOX
Container with network and credentials versus empty, isolated, egress-denied sandbox

Leaky sandbox

Shared-kernel container

creds mounted

Code calls metadata, internet

exfiltrates

Account compromise

Outcome, unsafe: Data leaves

Host at risk

Sealed sandbox

MicroVM or gVisor per session

no secrets

Egress denied, limits set

destroyed after

Nothing to take

Outcome, safe: No way out

Resources bounded

What interviewers probe next

  • "Why not containers with seccomp?" Shared host kernel; for hostile code the kernel attack surface is too large, and GPU drivers enlarge it further.
  • "How do you stop data exfiltration through allowed package downloads?" Mirror-only egress with no arbitrary query strings to external hosts, size limits on requests, and logging.
  • "How do you know the sandbox works?" Red-team it: escape attempts, metadata access, private-range scans, fork bombs; run these as regression tests.

What if?

What if · interview follow-ups

Hold your answer as the constraints change

A data-analysis agent writes and runs Python on files users upload, and the first prototype runs code directly on the API server.

  1. Start here

    Why is running code on the API server dangerous?

How it's scored

Weak: "Run it in Docker."

Hire: Strong boundary, no credentials, network denied by default, resource limits.

Strong Hire: Full environment design with brokered access, GPU isolation, lifecycle and outputs, and adapts cleanly to each constraint change.

Common mistakes

  • Mounting the runtime socket or user home directory.
  • Open internet "for pip".
  • Reusing sandboxes across users.
  • Executing sandbox outputs on the host.
You just read a free answer. Every topic opens its first 5 answers to anyone. Sign in and the count per topic goes to 10, and we keep track of how far you get in every topic.Google sign-in · free · no payment details
HOW DID IT GO?
0
READING SIGNED OUT

Signing in doubles your free answers, from 5 to 10 per topic, and the site starts remembering you: mastery per topic, bookmarks, and a next-focus recommendation. Free, no card.

Sign in free
UP NEXT ON YOUR JOURNEY
DISCUSSION · 0

No comments yet. Share a correction or a different way to answer it.