Current section
Files
Jump to
Current section
Files
README.md
# 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](https://github.com/smol-machines/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](docs/embedded-quickstart.md).
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](docs/supported-platforms.md#embedded-port-hosts). SmolBox
starts the helper from your Mix application without a separate HTTP server.
SmolBox 0.6.0 defaults to **SmolVM 1.34.0** for both backends.
For a separate SmolVM server, follow the [HTTP worker quickstart](docs/getting-started.md).
Held branches can receive their own non-secret environment values at release.
On Linux x86_64, both backends support opt-in allowlisted branch egress and
per-child HTTPS Bearer credentials. See [Managed branches](docs/managed-branches.md)
and [Upgrading to 0.6.0](https://github.com/hfiguera/smolbox/blob/v0.6.0/docs/upgrading.md#upgrade-to-060).
## 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.
- **Reuse a request's identity.** Submitting the same scoped ID and specification
returns its existing handle. A different specification under that ID is rejected.
- **Recover after a restart.** A durable store preserves execution records for
observation and cleanup. A command that may have run remains unknown when its
result is lost; SmolBox does not automatically run it again.
- **Track results and cleanup separately.** Input staging, output collection,
cancellation and VM deletion have their own states. Command success does not
imply that its machine has already been deleted.
## 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](docs/getting-started.md). The walkthrough
stops its demo supervisor after cleanup.
```elixir
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](docs/troubleshooting.md).
## Choose your next step
| What you want to do | Guide |
| --- | --- |
| Add supervision, profiles and durable storage | [Host integration](docs/host-integration.md) |
| Keep a machine and its files across commands | [Persistent machines](docs/persistent-machines.md) |
| Manage the lifecycle yourself | [Low-level client](docs/client.md) |
| Use registry images or prepared artifacts | [Images and registry artifacts](docs/images-and-registry-artifacts.md) |
| Run longer commands, background processes or a terminal | [Long commands](docs/long-running-exec.md) · [Terminals](docs/interactive-terminals.md) |
| Transfer files or retain data after machine deletion | [Guest files](docs/guest-files.md) · [Local volumes](docs/local-volumes.md) |
| Reuse prepared disk or memory state | [Exports](docs/machine-exports.md) · [Checkpoints](docs/managed-checkpoints.md) · [Branches](docs/managed-branches.md) |
| Configure networking or expose a guest service | [Network access](docs/network-access.md) · [Port mappings](docs/port-mappings.md) |
| Recover from failures or prepare maintenance | [Recovery](docs/recovery.md) · [Draining](docs/worker-draining.md) |
The [community workspace app](https://github.com/hfiguera/smolbox/tree/main/examples/community_workspace)
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](https://hfiguera.github.io/smolbox/) has longer worked examples.
## Deployment and support
SmolBox is ready for production use on documented configurations. Check the
[validated configurations](docs/supported-platforms.md#validated-configurations)
for the backend, host, features and storage you plan to deploy.
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](docs/security.md) before operating workers.
## Contributing
Source: [hfiguera/smolbox](https://github.com/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](https://github.com/hfiguera/smolbox/blob/main/scripts/ci/README.md).