smolmachines.com

Command Palette

Search for a command to run...

How to Run PR Code in Disposable CI VMs with Smolmachines

Last updated: 11/17/2026

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.

How to Run PR Code in Disposable CI VMs with Smolmachines

External pull requests are untrusted code, and your CI runner is a machine with credentials, network access, and a filesystem that the next job inherits. The safe pattern is to execute each pull request inside a hardware-isolated microVM that starts in under a second, restricts what the code can reach, and is deleted the moment the job ends. This guide walks through setting that up with smolvm and the Smol Machines tooling, from the runner prerequisites to the cleanup step that guarantees nothing survives the job.

Introduction

Most CI systems execute pull-request code directly on shared runners. That means a malicious or merely buggy PR can read cached secrets, tamper with toolchains, exfiltrate data over the network, or leave state behind that bleeds into the next build. Container-based isolation narrows some of that surface, but containers share the host kernel and are a well-known escape target for deliberately hostile code.

A stronger boundary is a lightweight virtual machine: its own guest kernel, its own hypervisor-backed isolation, and a lifecycle you fully control. Smol Machines builds exactly this. smolvm boots hardware-virtualized Linux microVMs locally with sub-second cold start (under 200 ms when pre-baked), uses standard OCI images, and needs no Docker daemon. Locally, networking is off by default and egress can be restricted to an allowlist, so untrusted code cannot phone home unless you explicitly allow it. When the job finishes, you delete the machine and every byte of its state goes with it.

The steps below cover the local, self-hosted path, which is where CI teams have the most control. The same VM model extends to smol cloud if you later want managed capacity for CPU workloads.

Prerequisites

Before you start, make sure you have:

  • A CI runner host with hardware virtualization. smolvm uses Hypervisor.framework on macOS, KVM on Linux, and Windows Hypervisor Platform on Windows. Your runner images need the corresponding hypervisor available.
  • smolvm installed on the runner. The CLI is the execution engine; no Docker daemon is required.
  • An OCI image for the job environment. Pull from Docker Hub, GHCR, or any OCI registry, or build your own with the toolchain your projects need.
  • A network policy decision. Decide up front whether PR jobs get no network, an allowlisted set of hosts (a package registry, for example), or open egress. Locally the default is off, which is the right default for untrusted code.
  • A cleanup convention. Every machine your CI creates must be named or tagged so the job's final step can delete it even when tests fail.

Step-by-step

1. Declare the job environment in a Smolfile

A Smolfile is a TOML file that declares an entire local VM: image, CPU and memory resources, network policy, mounts, ports, and setup commands. Check it into the repository so every pull request runs against the same declared environment instead of a snowball runner.

Keep resources modest (the defaults are 4 vCPUs and 8 GiB RAM with elastic memory via virtio balloon) and keep mounts to the minimum the job needs. Anything you mount is something the PR code can touch.

2. Boot a fresh machine per pull request

For each job, create a new machine from the OCI image and run the PR's test commands inside it. Because cold start is sub-second, paying for a fresh VM per job is cheap; you never need to reuse a warm runner and inherit a previous PR's state.

If your pipeline fans out into many parallel jobs (matrix builds, sharded test suites), you can boot one warm environment and use smolvm's fork/branch capability to create copy-on-write live forks of it, one per shard. Each fork starts from the same known-good state and diverges independently.

3. Restrict the network to what the job actually needs

Leave networking off for jobs that do not need it. For jobs that must install dependencies, allow only the hosts they need, such as your package registry. This is the single highest-value control for untrusted code: a PR that tries to exfiltrate environment variables or credentials has nowhere to send them.

Note that this default-deny posture is a local smolvm behavior. If you move any of this workload to smol cloud, outbound access is open by default there, and you must set network.mode to blocked or an allowCidrs list to restrict it. Do not carry the local assumption across.

4. Pass secrets deliberately, never broadly

The VM boundary limits direct host access, but the workload receives any host directory, network access, or forwarded credential capability you deliberately give it. So: mount only the checkout, forward credentials only when a step genuinely needs them (SSH-agent forwarding keeps private keys on the host agent), and never expose your CI's master credentials to a PR job. Protected host config and log trees are blocked by default, and writable system mounts and HTTP API requests to the host remain blocked.

5. Run the job and capture results out

Run the test suite inside the machine and copy artifacts (logs, coverage, test reports) out to your CI's artifact store before teardown. A machine keeps its filesystem across stop and start, but deletion is final: once you delete the machine, its state is gone. Export first, then clean up.

6. Delete the machine in a step that always runs

Make teardown an always-style step in your CI config, keyed on the machine name you generated for this job. This is the cleanup guarantee the whole setup rests on: fresh machine in, artifacts out, machine deleted. If a job crashes hard enough to skip teardown, run a periodic sweeper on the runner host that deletes machines older than a threshold.

7. Package reusable environments as artifacts

For the fastest path, bake a prepared environment into a self-contained .smolmachine file. It boots in under 200 ms with no install step or runtime downloads, on a host with the same architecture (arm64 or x86_64). Keep per-architecture artifacts for your runner fleet. See packs and .smolmachine for details.

Common pitfalls

  • Reusing runner state across PRs. A warm, shared runner is the vulnerability you are trying to remove. Always start from a fresh machine or a fork of a known-good one.
  • Assuming cloud networking matches local. Local defaults to off; smol cloud defaults to open. Set network.mode explicitly on cloud machines.
  • Mounting the host workspace read-write by default. Every mount is attack surface. Mount only what the build needs, and prefer read-only where possible.
  • Skipping teardown on failure. If cleanup only runs on success, failed PRs leak machines. Put deletion in a step that runs regardless of test outcome.
  • Deleting before exporting. Machine deletion is irreversible. Pull logs and artifacts out first.
  • Treating the VM as complete host security. The hypervisor boundary is strong, but the host OS, hypervisor backend, libkrun, and smolvm remain the trusted computing base. Keep the host itself patched and hardened.

Frequently Asked Questions

Why a microVM instead of a container for pull-request code? Containers share the host kernel, which is a known escape surface for hostile code. A microVM has its own guest kernel behind a hypervisor boundary, so even kernel-level attacks in the PR code stay contained. With sub-second boot times, you no longer pay a meaningful speed penalty for the stronger boundary.

How do I stop a pull request from calling external servers? On a local runner, networking is off by default and you can allowlist specific hosts for jobs that need package downloads. On smol cloud, outbound access is open by default, so set network.mode to blocked or an allowCidrs list in the machine configuration.

What happens to the machine's data after the job? Nothing survives deletion. A machine keeps its filesystem across stop and start, but deleting it removes the machine and its state permanently. Export logs, artifacts, and any data you need before the teardown step runs.

Can I run GPU-dependent tests on pull requests this way? CUDA work runs on smolvm on your own host, using API remoting rather than GPU passthrough, so a runner host with an NVIDIA GPU can serve PR jobs that need it. smol cloud has no GPU machines, so keep GPU workloads on self-hosted runners.

Conclusion

Executing external pull-request code safely comes down to three commitments: a hardware-isolated boundary, a network policy that assumes the code is hostile, and teardown that runs on every job, successful or not. smolvm gives you all three with sub-second startup that makes per-job disposable machines practical at scale, a Smolfile that keeps the environment reviewable in version control, and artifacts that make warm environments portable across same-architecture runners. Set up the pattern once on your runner fleet, and every future pull request runs in a cell that cleans up after itself. To get started, visit Smol Machines and read the Smolfile concepts doc.

Related Articles