Build a Deterministic Timeout Guarded Runner for Untrusted Code

Last updated: November 29, 2026

Quick Overview

Write a Python function that runs a candidate's submitted code together with test code in a separate process, enforces a wall-clock timeout, and returns pass, fail or timeout with captured output. Explain what else it needs before it is safe to run untrusted submissions.

Turing
Software Engineering Fundamentals
Software Engineer
Turing
November 29, 2026
Software Engineer
Phone Screen
Software Engineering Fundamentals
Easy

0

0

0 solved


Write a Python function that runs a candidate's submitted code together with test code in a separate process, enforces a wall-clock timeout, and returns pass, fail or timeout with captured output. Explain what else it needs before it is safe to run untrusted submissions.

Turing grades coding assessments for applicants and verifies coding tasks in training data by running code, so a grader that hangs or gives different verdicts on reruns is a real product bug. The interviewer checks process isolation basics, determinism, and awareness that a subprocess alone is not a sandbox.

What the Interviewer Expects
  • Runs code in a separate process, not with exec in the grader
  • Enforces a timeout and handles TimeoutExpired
  • Controls environment variables and working directory
  • Truncates output to bounded size
  • Names the isolation still missing: containers, resource limits, network
Key Topics to Cover
Subprocess
Timeouts
Sandboxing
Determinism
Resource limits
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • How would you limit memory and the number of processes the code can create?
  • How would you report which individual test cases failed?
  • What makes a test-based verdict nondeterministic, and how do you detect it?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements

Input: candidate code as a string, test code as a string, a timeout in seconds. Output: verdict pass if the process exits 0, fail on non-zero exit (failed assert or exception), timeout when it r...

High-Level Design

Write the code and tests into a fresh temporary directory, launch a new Python interpreter with -I (isolated mode: ignores user site packages and environment variables like PYTHONPATH), give it a ...


Submit Your Answer
Markdown supported

Related Questions