Design a Multi-Tenant Sandbox That Executes Model-Written Python Code
Last updated: November 29, 2026
Quick Overview
Design the service behind a code interpreter tool that runs Python written by the model on user data, with per-conversation state, file access, strict isolation and fast startup.
OpenAI
November 29, 20260
0
0 solved
Design the service behind a code interpreter tool that runs Python written by the model on user data, with per-conversation state, file access, strict isolation and fast startup.
ChatGPT's data analysis feature and the API's code interpreter execute untrusted, model-generated code for millions of users. The interviewer probes isolation technology choices, warm pools for low startup latency, stateful session management and resource abuse controls.
What the Interviewer Expects
- Pick an isolation boundary (microVMs or gVisor) and justify it over plain containers
- Keep warm pools so session start is under a second
- Maintain per-session state (Python kernel, files) across tool calls with idle expiry
- Restrict network egress and filesystem access
- Enforce CPU, memory, disk and wall-clock limits
- Return stdout, errors, images and files to the model and user
Key Topics to Cover
How to Approach This
- Start by clarifying functional and non-functional requirements with the interviewer.
- Estimate the scale: QPS, storage, bandwidth. This drives your design decisions.
- Draw a high-level architecture first, then deep dive into 1-2 critical components.
- Discuss trade-offs explicitly (e.g., consistency vs availability, SQL vs NoSQL).
- Address failure scenarios, monitoring, and how the system handles 10x traffic spikes.
Possible Follow-up Questions
- How do you handle a session idle for 30 minutes that the user then resumes?
- How would you allow pip installs safely?
- How do you detect crypto mining or other abuse?
- How do you scale to sudden 10x demand when a new model makes the tool popular?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
- Model issues
execute(code)in a session; output (stdout, stderr, rich display images) returned within seconds. - State persists across calls in the same conversation (variables, files in `/mnt/dat...
High-Level Design
- Session manager maps
conversation_id -> sandboxand stores session metadata. - Sandbox hosts run Firecracker microVMs (each with a Jupyter-style kernel) managed by a host agent.
- **Wa...