You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Replace the TCP socket RPC to the sandbox with a multiprocessing pipe #57
The grader runs student code in a separate process and talks to it over a hand-rolled RPC: the sandbox process starts an asyncio TCP server on 127.0.0.1 (_student_code_runner.py, main/handle_client), prints host, port on stdout, and the grader connects a socket and exchanges newline-delimited JSON messages (fixture.py, _SandboxBase). This is the single largest piece of the codebase — roughly 900 lines in _student_code_runner.py plus the client half in fixture.py.
Why change it
Hand-rolled framing. We reimplement an RPC loop (message dispatch, a 10 MB line limit, JSON encode/decode on both ends, start/query/query-function/query-setup message types) that a higher-level primitive would give us for free.
Open TCP port with no auth. Any process in the container's network namespace can connect to the sandbox port and drive the protocol or read responses, and socket is not in the default import blacklist. A pipe or Unix domain socket removes that exposure.
Windows-specific plumbing.main selects a ProactorEventLoop, and there are sys.platform == "win32" branches throughout. (Note: this is also why we can't simply switch the TCP server to a Unix domain socket — asyncio.start_unix_server is Unix-only, so that narrowing belongs with this rework rather than as a standalone change.)
Transport plumbing leaks into the design. The host, port handshake over stdout, HOST, the socket timeouts, and the connect/read helpers all exist only to move bytes.
Proposed direction
Replace the socket transport with multiprocessing using a Pipe (or ProcessPoolExecutor), keeping the same responsibilities:
Privilege drop stays, via the child's preexec_fn / an initializer (what drop_privileges does today in the Popenpreexec_fn).
Per-call timeout maps to recv/future timeouts.
stdout/stderr capture of student code is unchanged.
Activity
Replace the sandbox socket RPC with a multiprocessing pipe (#59)