SmolBox

Run Python, JavaScript and other programs in disposable or retained Linux VMs from Elixir.

SmolBox is a client and supervised execution runtime for smolvm. SmolBox runs VMs through a local Embedded Port helper or connects to an external smolvm HTTP worker. It tracks command identity, results and cleanup under your application's supervision tree.

Start here

For a first local run, follow the Embedded Port quickstart. It installs a verified native bundle and runs one offline command on Apple Silicon, Linux x86_64 or Linux ARM64. You need Elixir 1.18 or later and the host prerequisites. SmolBox starts the helper from your Mix application without a separate HTTP server.

SmolBox 0.5.1 defaults to SmolVM 1.34.0 for both backends. For a separate SmolVM server, follow the HTTP worker quickstart.

Why use SmolBox?

Executing a command is only part of integrating a worker. Your application also needs to handle duplicate requests, lost responses, restarts and leftover VMs.

What execution looks like

This fragment illustrates submitting a command to an already configured runtime. It assumes SmolBoxDemo.Runtime is running and artifact and profile are available in the same code context. For a complete runnable example, use Getting started with an HTTP worker. The walkthrough stops its demo supervisor after cleanup.

alias SmolBox.{Command, ExecutionSpec}

argv = ["python", "-c", "print(6 * 7)"]
{:ok, command} = Command.new(argv, timeout_secs: 10)

{:ok, spec} =
  ExecutionSpec.new(
    scope: "demo",
    id: "answer-001",
    artifact: Map.drop(artifact, ["path"]),
    profile: profile,
    command: command
  )

{:ok, handle} = SmolBox.submit(SmolBoxDemo.Runtime, spec)
{:ok, ^handle} = SmolBox.submit(SmolBoxDemo.Runtime, spec)

{:ok, execution} =
  SmolBox.await(SmolBoxDemo.Runtime, handle, 90_000)

%{state: :completed, result: result} = execution
%{exit_code: 0, stdout: stdout} = result

IO.write(stdout)
# Prints: 42

The second submission reuses the execution. The specification uses the image identity from artifact and the registered profile created during setup. Handle errors, nonzero exits and unknown outcomes in application code. An await/3 timeout does not cancel the command. Inspect cleanup with SmolBox.fetch/3; see Troubleshooting.

Choose your next step

What you want to do Guide
Add supervision, profiles and durable storage Host integration
Keep a machine and its files across commands Persistent machines
Manage the lifecycle yourself Low-level client
Use registry images or prepared artifacts Images and registry artifacts
Run longer commands, background processes or a terminal Long commands · Terminals
Transfer files or retain data after machine deletion Guest files · Local volumes
Reuse prepared disk or memory state Exports · Checkpoints · Branches
Configure networking or expose a guest service Network access · Port mappings
Recover from failures or prepare maintenance Recovery · Draining

The community workspace app provides a Phoenix walkthrough using its pinned SmolBox 0.3.0 dependency. It includes persistent machines, commands, a terminal and PostgreSQL recovery. The engineering blog has longer worked examples.

Deployment and support

SmolBox relies on smolvm for VM isolation. Your deployment controls worker access, image approval, host resource limits, networking, credentials and storage. Admission reservations do not enforce host quotas. Offline networking is the default, and retained machines remain until explicitly deleted. Read Deployment boundaries before operating workers.

Check the host, toolchain and feature requirements before selecting a backend. Supported platforms

Contributing

Source: hfiguera/smolbox. Toolchain pins are in .tool-versions. Run mix ci for deterministic checks without a real worker. Build the documentation with MIX_ENV=dev mix docs --warnings-as-errors, then run MIX_ENV=dev mix smolbox.ci.docs to check local links and fragments. Live worker checks are a separate operation described in the repository's CI guide.