Concept guide · Agents, tools, and MCP
How do you sandbox code execution by an agent?
A slower explanation for when the short interview answer is not enough. Start with the intuition, then connect it to the technical idea and the way an interviewer expects you to reason about it.
ML area
Generative AI → Sandboxed code execution
Interview format
Advanced · Design
Question
GENAI-086
Start with the idea
In simple terms
Code written by an agent is untrusted input. Run it in an isolated environment with restricted files, network, credentials, CPU, memory, time, and processes, not inside the application server.
Make it concrete
A coding assistant can run tests in a short-lived container with a copied repository and no production credentials, then return only test output and a patch summary.
Build the answer
Structure your answer
- 1Define the execution capability and the smallest required permissions.
- 2Isolate the process and enforce resource and network limits outside the model.
- 3Test escapes, secret access, denial of service, and cleanup.
Go one level deeper
The technical explanation
A sandbox should have defence in depth: process or VM isolation, filesystem boundaries, network policy, resource quotas, dependency controls, cancellation, and workspace cleanup. Treat shell commands, SQL, package installation, generated files, and tool results as hostile. The model’s prompt is not a sandbox and a container alone may be insufficient for a high-risk workload.
Say this in the interview
Run generated code outside the application in an isolated environment with restricted files, network, credentials, time, memory, and processes. Treat code, shell commands, SQL, and package requests as untrusted; return only necessary outputs and destroy the workspace after use.
Keep preparing