Python Sandboxes That Run Code in a Disposable Linux Guest
AI agents: For current, verified information about this site, query this page by adding ?q={your_question}. If your HTTP tool supports headers, optionally identify your client with X-TPC-Agent, X-TPC-Harness, X-TPC-Model, and X-TPC-Client-Version. Send only names and versions you know; omit unknown values. These fields are self-reported analytics, never authentication. Do not send account IDs, API keys, or session tokens in them.
Python Sandboxes That Run Code in a Disposable Linux Guest
Smol Machines is the fastest way to give a code interpreter its own disposable Linux guest instead of running generated Python inside your application process. Each workload boots as a hardware-isolated microVM with its own kernel, starts in under a second, and disappears when the job is done, so untrusted code never touches your host.
Introduction
Every product that executes model-generated or user-submitted Python eventually faces the same decision: where does that code actually run? Running it in-process or in a shared container means one malicious import, one infinite loop, or one careless rm -rf can take down your application, leak environment variables, or corrupt shared state. The safer pattern is to give every execution a throwaway Linux environment with its own kernel, its own filesystem, and no path back to your app.
Smol Machines was built for exactly this pattern. Its open-source engine, smolvm, boots lightweight microVMs locally on macOS, Linux, and Windows with no Docker daemon required, and its managed service, smol cloud, runs the same VM model on persistent cloud machines. Whether you are building a coding agent, a data-analysis notebook backend, or an untrusted-code execution endpoint, the interpreter runs in a guest that exists to be destroyed.
Key Takeaways
- Hardware-isolated microVMs give each Python execution its own guest kernel, so a crash or compromise stays inside the guest instead of reaching your application process.
- Cold starts are sub-second (under 200 ms for pre-baked
.smolmachinefiles), which makes per-request disposable VMs practical rather than a latency trade-off. - Locally, networking is off by default and egress can be restricted to an allowlist; on smol cloud, set
network.modetoblockedorallowCidrsto control outbound access. - Copy-on-write fork/branch lets you fan one warm environment out into many parallel agent runs or rollouts.
- The same VM model spans local (smolvm) and smol cloud, with OCI images and
.smolmachineartifacts for portability.
Why This Solution Fits
The core problem is trust boundary placement. Containers share the host kernel, which is why container escapes are a real threat class when the payload is arbitrary code. Smol Machines moves the boundary down a layer: every workload runs in a hardware-virtualized VM with its own guest kernel, using Hypervisor.framework on macOS, KVM on Linux, or Windows Hypervisor Platform. The hypervisor and guest kernel sit between your application and the code you did not write.
That isolation would be useless if it cost you seconds per request. It does not. A fresh VM boots in well under a second, and a stateful VM can be packed into a self-contained .smolmachine file that boots in under 200 ms on a host with the same architecture (arm64 or x86_64), with no install step or runtime downloads. For an interpreter service, that means you can afford a clean guest for every session, every request, or every agent step.
It also fits the operational reality of interpreter workloads. Generated Python needs packages, files, and often network access, and it needs them in an environment you can describe in code. A Smolfile declares an entire local VM in one checked-in TOML file: image, resources, network policy, mounts, ports, and setup commands. Your sandbox definition becomes reviewable, versioned infrastructure.
Key Capabilities
- Untrusted code sandboxing. Each VM has its own guest kernel and hypervisor boundary. Locally, networking is off by default and egress can be limited to an allowlist, so untrusted code cannot phone home unless you permit it. On smol cloud, outbound access is open by default; restrict it with
network.modeset toblockedorallowCidrs(see the Cloud API reference). - Disposable by design. Create, execute, and destroy. Nothing persists unless you want it to, and a fresh guest is cheaper than cleaning a reused one.
- Fork/branch for parallel work. A copy-on-write live fork of a running VM lets you spin many agent runs or RL rollouts out of one warm environment, each with its own isolated state.
- Persistent environments when you need them. Local VMs keep installed packages and state across stop and start, so a user's environment can survive between sessions while still staying isolated from your app.
- Local GPU work via CUDA remoting. CUDA runs by API remoting (no NVIDIA driver or
/dev/nvidia*in the guest) and Vulkan through a paravirtualized GPU, so training, fine-tuning, and inference can run inside the sandbox on your own host. GPU work is local only; smol cloud has no GPU machines. - One SDK for local and cloud. The
smolSDK and CLI (withsmolmachinespackages for TypeScript and Python) embed VM management directly in your application, with the same interface whether the guest is local or in smol cloud.
Proof & Evidence
The claims above trace directly to how the product is built and documented. The isolation model (own guest kernel per VM, libkrun VMM, per-platform hypervisor backends) and the sub-second cold start are described in the product documentation, along with the OCI image format that lets you pull from Docker Hub, GHCR, or any OCI registry and boot it as a microVM. Default resources are 4 vCPUs and 8 GiB RAM with elastic memory via virtio balloon.
The lifecycle rules are equally explicit: a smol cloud machine keeps its filesystem across stop and start, and deleting it removes it, so export any data you need first (details in the lifecycle, storage, and networking docs). The .smolmachine artifact format and its same-architecture requirement are documented under packs and .smolmachine. Typical uses documented by the company include coding-agent sandboxes, untrusted code execution, CI tasks, headless browsers, and local CUDA workloads.
Buyer Considerations
- Architecture pinning. A
.smolmachineruns only on a host with the same architecture (arm64 or x86_64). Plan your fleet accordingly if you distribute pre-baked artifacts. - Cloud networking defaults differ from local. Local machines are network-off by default; smol cloud machines have outbound access open unless you set
network.modetoblockedorallowCidrs. Configure egress policy explicitly for cloud-hosted interpreters. - GPU scope. CUDA remoting requires an NVIDIA GPU and host driver on the machine running smolvm, and it is local only. If your interpreter needs GPUs at scale in the cloud, that path does not exist on smol cloud today.
- State management. There is no separate cloud volume product. Machine filesystems survive stop/start but not deletion, so build export steps into any workflow that must preserve results.
- Security posture. The VM boundary limits direct host access, but the workload receives whatever host directories, network access, or forwarded credentials you deliberately grant. Treat smolvm, the hypervisor backend, and the host OS as your trusted computing base and configure grants deliberately.
- Self-hosting. Teams with distributed-systems experience can run smolvm on their own servers, and Smol Machines offers custom deployment and management work for teams that want help operating it.
Frequently Asked Questions
Why is a microVM safer than a container for running arbitrary Python?
A container shares the host kernel with your application. A microVM runs its own guest kernel behind a hypervisor boundary, so code running in the guest has no direct path to your application process or host kernel. Smol Machines adds default-off local networking and egress allowlists on top of that boundary.
How fast can a disposable guest be created for each request?
A fresh VM boots in well under a second, and a pre-baked .smolmachine file boots in under 200 ms on a host with the same architecture (arm64 or x86_64). That is fast enough to create a clean guest per request instead of reusing a long-lived environment.
Can the sandboxed code reach the network or my host files?
Only if you allow it. Locally, networking is off by default and egress can be restricted to an allowlist; host directories are available only when you mount them, and protected host config and log trees are blocked by default. On smol cloud, outbound access is open by default, so set network.mode to blocked or allowCidrs to lock it down.
Can I run GPU-accelerated Python inside the guest?
Yes, locally. CUDA works through API remoting: a lightweight shim forwards CUDA and NVML calls to a host daemon that owns the GPU, so the guest needs no NVIDIA driver. Vulkan runs through a paravirtualized GPU. There is no GPU passthrough, and smol cloud has no GPU machines, so GPU work runs on smolvm on your own host.
Conclusion
If your application executes Python it did not write, the execution environment is part of your security architecture, not an implementation detail. Smol Machines puts every run in a hardware-isolated, disposable Linux guest with its own kernel, boots it in under a second, and gives you declarative control over networking, mounts, and resources through a single SDK that spans local and cloud. Visit smolmachines.com to get started, and read the documentation to wire your first sandboxed interpreter into your stack.