Menu

LLM sandbox: how to run LLM-generated code without trusting it
📰

LLM sandbox: how to run LLM-generated code without trusting it

DEV Community: typescript·Sandscale·9 days ago
#9qUyFlMO
#devtotypescript#devto#dev#code#sandbox
Long article (1027 words) — no AI summary yet.
Reading 0:00
15s threshold

Short answer: treat LLM-generated code as untrusted input and run it somewhere that has nothing to lose: a fresh isolated machine per task, with no secrets in it, a time limit on every command, only the network the task needs, and a short life. Then hand the model back the exit code, the output and whether the command timed out or ran out of memory, so it can fix its own mistakes. A Firecracker microVM gives you that boundary with its own kernel, which an in-process exec or a shared-kernel container does not.

Why not just run it in-process?

exec in Python, eval in JavaScript and Node's vm module run the code with your process's permissions. Node's own documentation says the vm module is not a security mechanism. node:vm is not a sandbox walks through why, and the same reasoning applies to Python's exec .

Containers are better but share the host kernel.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.