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.…