Safety, Security & Responsible AI·Question 42 of 70Advanced

You're doing a security review of a coding agent that executes model-generated code. What's your threat model and controls?

Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.

Model answer: the part to lead with

The defining risk: you are running attacker-influenceable code (the model is injectable via the repo, issues, docs, or dependencies it reads), so the sandbox is the primary control, not a nice-to-have.

Full worked answer with diagram

The defining risk: you are running attacker-influenceable code (the model is injectable via the repo, issues, docs, or dependencies it reads), so the sandbox is the primary control, not a nice-to-have.

Threat model. (1) Injected instructions in the codebase/issue/tool output make the agent write malicious code or run malicious commands. (2) The generated code exfiltrates source or secrets. (3) It reaches into infrastructure (cloud creds, prod DB) via ambient credentials. (4) It installs a malicious dependency (supply chain). (5) Resource abuse - fork bombs, crypto mining, runaway spend. (6) Sandbox escape.

Controls:

  • Strong sandbox - container with a hardened runtime (gVisor, Firecracker microVM, or WASM for the strictest), throwaway filesystem, non-root, seccomp/AppArmor, tight CPU/memory/time/disk limits. Assume the code is hostile.
  • No network egress by default - the single most important control (kills exfil and remote payloads). If network is needed, allowlist specific hosts (package registry, the APIs the task requires) and log all egress.
  • No ambient credentials in the sandbox - never mount cloud creds, prod DB strings, or SSH keys into the execution environment. If the task needs an external call, broker it through a gated, scoped, audited proxy rather than handing the sandbox a token.
  • Filesystem scoping - mount only the working directory; deny access to host paths, ~/.ssh, ~/.aws, env secrets.
  • Dependency hygiene - pin/lock, scan installed packages, prefer a vetted mirror, disallow arbitrary pip install from unknown indexes; watch for typosquatting.
  • Human approval for consequential actions - merging, pushing, deploying, deleting, or anything touching prod goes behind an explicit gate; auto-run only reversible, sandboxed steps.
  • Output handling - the code's output re-enters the model's context and can itself carry injection, so treat it as untrusted too.
  • Observability - log every command, every file touched, every network attempt; alert on anomalies; support kill-switch and replay.

The senior framing: sandboxing contains blast radius, egress-blocking + no-ambient-creds breaks exfil, and approval gates cap irreversible damage - layered so no single failure is catastrophic.

Worth sketching. Drawing the two cut edges, egress and credentials, explains why the sandbox is the control rather than a convenience.

flowchart LR
    A["Repo, issues, docs, deps"] -->|"injectable text"| B["Model writes code"]
    B --> C["Sandbox: microVM, non-root, throwaway FS"]
    C -->|"egress denied by default, allowlist only"| D["Internet"]
    C -->|"no ambient creds mounted"| E["Cloud and prod database"]
    C --> F["stdout re-enters the context, still untrusted"]
    F --> B
    C --> G["Push, merge, deploy behind approval"]

What a good answer covers

  • The defining risk: you are running attacker-influenceable code (the model is injectable via the repo,…
  • (1) Injected instructions in the codebase/issue/tool output make the agent write malicious code or run…
  • (2) The generated code exfiltrates source or secrets
  • (3) It reaches into infrastructure (cloud creds, prod DB) via ambient credentials
  • (4) It installs a malicious dependency (supply chain)

Key terms: running attacker-influenceable code · Threat model · Controls · Strong sandbox · No network egress by default · allowlist · Filesystem scoping · Dependency hygiene · Human approval for consequential actions · Output handling

Interviewer follow-ups to expect

  1. Why is blocking network egress the highest-leverage single control?

  2. Why must credentials never live inside the sandbox even if the task "needs" them?

  3. The generated code's stdout goes back to the model - what's the risk there?

Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep