r/lowlevel • u/AuthorJazzlike3254 • 13d ago
I'm building a lightweight code execution sandbox from scratch — would love some architecture feedback
I've been working on a project called SuperSand for a while now.
The basic idea is pretty simple: I want to run untrusted user code securely, but with as little overhead as possible. Think something in the direction of serverless/code execution platforms, but I'm building most of the sandboxing layer myself using Linux primitives instead of putting Docker/Kubernetes underneath everything.
Right now I have a Go service that handles requests, IPC and sandbox management. The sandbox itself uses Linux namespaces, resource limits, isolated filesystems, etc.
Recently I've been experimenting with pre-warmed workers.
Instead of creating a completely new sandbox for every request, I can keep a bunch of isolated workers alive, mount the user's workspace when a request arrives, execute the code, clean everything up, and reuse the worker.
This is where I'm currently stuck thinking about architecture.
I want SuperSand to eventually handle a LOT of small executions without needing ridiculous amounts of hardware. If a user runs something for several minutes, I don't necessarily want one worker sitting there occupied the entire time.
I've even been researching process checkpoint/restore so theoretically I could pause an execution, free the worker for something else, and resume it later.
I also considered going even further and doing runtime-level scheduling for JavaScript — basically controlling execution myself and giving different workloads execution time in smaller slices.
For JS I'm looking at QuickJS, mostly because spinning up Node/Bun for every tiny execution can eat a surprising amount of RAM.
I'm probably overthinking some of this 😅, but that's also part of why I'm building it. I want to understand how far I can push Linux processes/namespaces and how these execution platforms actually work underneath.
If you've worked on container runtimes, serverless infrastructure, Linux sandboxing, schedulers, CRIU/checkpointing, QuickJS, etc., I'd really like to hear your thoughts.
If you were trying to run thousands of small untrusted code executions on limited hardware, how would you approach the worker/scheduling architecture?
Also very interested in hearing what I'm doing wrong. 😅
2
u/ReDucTor 13d ago edited 13d ago •
This seems like a bad idea, if your mounting and unmounting things it seems like your heavily I/O bound per request. And process per request never truely scales.
Typically a cold start is doing things like loading configs, caching, etc all of which vary based on a workspace so switching mounts seems like you might still hit this I/O and you also have a bunch of security risks.
This seems like a nightmare, a process might have network connections, files opened, etc all of which are not in the same state when you restore, even the PID might be in use and change.
It feels like a whole lot of over engineering into something which will be fragile, slow and hard to debug edge cases that would show as you try to even hit production.
1
u/thenewelon 11d ago
Use a bounded queue feeding isolated QuickJS worker processes, with cpu.max and memory.max limits; let Linux schedule them. Returning nonzero from QuickJS's interrupt handler aborts the script, so it won't give you resumable time slices.