vm
kind: vmname: sandboxspec: driver: smolvm image: alpine cmd: [sleep, infinity]The resource declares one virtual machine and keeps it running while the resource is wanted. A driver makes the machine; the only one today is smolvm, which runs an OCI image as a hardware-virtualized microVM with the smolvm CLI. Everything above the machine (hooks, the runy binary, ssh, the daemon link, proxy names, in-place updates) is the kind’s and does not depend on the driver.
The kind used to be called smolvm. There is no alias: kind: smolvm is an unknown kind, and ids are vm/<name>.
driver is required. Without it the resource is Error with “driver is required (known drivers: smolvm)”, and a name the daemon does not know is “unknown driver x (known drivers: smolvm)”. image, the driver’s own image source (smolvm.smolfile), from, template or branch must be given. Unknown keys are rejected.
| field | default | |
|---|---|---|
driver |
the machine backend, smolvm |
required |
image |
the OCI image | required unless smolvm.smolfile or from gives one |
from |
a pack to create the machine from instead of an image, see a machine from a pack; exclusive with image, cmd and smolvm.smolfile |
none |
template |
a template to create the machine from, see instances of a template | none |
branch |
a running vm to branch the machine from, see branches; exclusive with image, from, template, cmd and smolvm.smolfile |
none |
branchable |
start the machine as a branch source, so other vms can branch it, see branches | false |
pack |
where the pack signal writes a pack of this machine, see a machine from a pack |
none |
cmd |
the workload command, a list | the image’s ENTRYPOINT/CMD |
machine |
the smolvm machine’s name | <namespace>-<name>, <name> at the top level |
cpus |
--cpus |
smolvm’s |
memory |
--mem, in MiB |
smolvm’s |
net |
--net |
smolvm’s |
egress |
{ allow, deny, block_private }: what the guest may reach, see egress; turns net on |
none |
ports |
-p entries, HOST:GUEST[/udp], passed as written |
[] |
volumes |
-v entries, HOST:GUEST[:ro]; a host path is resolved against the workspace root |
[] |
env |
-e KEY=VALUE, a map of scalars like a process’s |
{} |
workdir |
-w |
smolvm’s |
user |
-u |
smolvm’s |
runy |
copy a Linux build of the runy binary into the machine, see runy inside the machine |
true |
hooks.create |
shell commands to run inside the machine once it first runs, see hooks | [] |
hooks.start |
shell commands to run inside the machine after every start, see start hooks | [] |
hooks.remove |
shell commands to run inside the machine before it is deleted | [] |
ssh |
true or { user, keys }: authorize keys and start sshd, see ssh |
off |
daemon |
link to the runy daemon inside the machine, see daemon; needs runy: true |
false |
routes |
the guest’s port resources the proxy routes, see routes; an explicit selection needs daemon: true |
all with daemon: true, none without |
workspaces |
remote paths registered as workspaces on that daemon | [workdir] |
metrics |
sample CPU, memory and disk while the machine runs: true, false, or { interval } in seconds (5 to 3600), see metrics |
true, every 60 s |
journal.max_lines |
lines the resource’s journal keeps, metrics samples included | 5000 |
storage |
--storage, in GiB |
smolvm’s |
stop_timeout |
--stop-timeout, in seconds |
smolvm’s |
persistent |
keep the machine when the resource is removed, and report an Error instead of recreating it, see persistent |
false |
secrets |
the secrets the machine may use and how, see secrets | none |
smolvm |
the options only the smolvm driver understands, see driver options | none |
The flags in the table are the smolvm driver’s.
Driver options
Section titled “Driver options”Options that only one driver understands sit in a block named after it, so the common keys stay the same for every driver. The smolvm block takes:
| field | default | |
|---|---|---|
smolfile |
a Smolfile (TOML), relative to the workspace; spec fields override it | none |
overlay |
--overlay, in GiB |
smolvm’s |
kind: vmname: sandboxspec: driver: smolvm image: alpine net: true smolvm: overlay: 10The flat keys smolfile and overlay are unknown keys, and a block for a driver other than the selected one is an error. A common key the driver cannot honour is an Error naming the driver (“driver x does not support …”). Which keys change live, need a stop or need a recreate is the driver’s answer; the table below is smolvm’s. RUNY_SMOLVM names the smolvm binary to run instead of smolvm from the PATH.
Status
Section titled “Status”{ "driver": "smolvm", "machine": "acme-sandbox", "state": "running", "pid": 11874, "image": "alpine", "cpus": 2, "memory": 2048, "ports": [{ "host": 8080, "guest": 8080, "proto": "tcp", "name": null, "domain": "8080.acme-sandbox.vm.runy.localhost", "url": "http://8080.acme-sandbox.vm.runy.localhost" }], "ssh": null, "data_dir": "/Users/me/Library/Caches/smolvm/vms/3f9c1e2", "restarts": 0, "reason": null, "ready": true, "runy": { "version": "0.7.0", "sha256": "9b1f4c0e..." }, "daemon": null, "metrics": { "time": 1794441600000, "cpu_percent": 4.87, "cpus": 8, "memory": { "used": 4294967296, "total": 16750000000, "available": 11811160064 }, "disk": { "used": 13207470080, "total": 64424509440 } }, "egress": null }driver is the driver’s name. state is the driver’s (created, running, stopped), starting between create and the first running seen, and failed when the resource is Error. ports is parsed from the spec’s entries; the protocol is tcp unless the entry says /udp, and a bare PORT is the same on both sides. data_dir is null until known. restarts and reason are the driver’s restart_count and state_reason. ready is true once the runy binary is in place and the create and start hooks have passed (at once when there are none). state is updating while an in-place update runs. runy is the version and sha256 of the binary copied in, null with runy: false. name, domain and url of a port entry are its proxy name (name is null for a mapping named by its guest port, domain and url are null for udp). ssh is { domain, port, user, command } with ssh and null without. daemon is { state, version, reason } with daemon and null without. metrics is the latest sample (time in unix milliseconds, sizes in bytes, a part the driver could not read left out), null before the first and while the machine is stopped. pack is { path, size, created } for the last pack the pack signal wrote (created in unix milliseconds), null until this daemon has made one; state is packing while the signal runs. template is { id, build, stamp } for an instance of a template, null otherwise. branchable is true while the machine runs as a branch source, as runy started it. branch is { of, at } for a branch, the vm it was branched from and when (unix milliseconds), null otherwise. egress is { refused, recent } with an egress policy, null without one.
The daemon polls the machine every 5 seconds and republishes when state, pid, reason or branchable changed. A machine found stopped on its own, because the workload exited or someone stopped it by hand, is published as stopped and not restarted. The restart signal or a re-apply starts it.
The workload’s output is streamed to the resource’s journal, from each start on: a restart does not replay the lines of the previous run.
Ensure
Section titled “Ensure”The machine is brought up in the background, never inside apply:
| the machine | what runy does |
|---|---|
| does not exist | create, then start |
| is ours, spec unchanged | start, unless it is running |
| is ours, spec changed in place (see below) | the driver’s resize or update (smolvm: smolvm machine resize or smolvm machine update), then start; the machine is not recreated |
is ours, its identity changed, not persistent |
stop it, delete it, create and start again; the journal says “spec changed: recreating machine x” |
is ours, its identity changed, persistent |
the resource is Error |
A failing driver command makes the resource Error with the command and the driver’s message. Without smolvm on the PATH the resource is Error with the install commands below.
In-place updates
Section titled “In-place updates”A changed spec does not recreate the machine unless its identity changed. Each key is reconciled with the cheapest operation the driver has. The kind fixes the prepare keys and treats driver as an identity key (another driver is another machine); the driver classes every other key. The table is the smolvm driver’s:
| class | keys | on a change |
|---|---|---|
| identity | driver, image, cmd, user, smolvm.smolfile, stop_timeout, machine, egress.deny, egress.block_private |
the machine is recreated, or the resource is Error with persistent: true |
| live | cpus, memory, storage, smolvm.overlay |
when the value only grows, smolvm machine resize on the running machine, no reboot |
| stopped | ports, volumes, env, workdir, net, egress.allow, branchable, and cpus or memory when they shrink |
stop, one smolvm machine update, start: the guest reboots once, the disk and the work of the create hooks survive, and the create hooks do not run again; branchable is a flag of the start alone, so a change of it alone is a stop and a start |
| prepare | persistent, hooks, runy, ssh, daemon, routes, workspaces, metrics, journal, pack, secrets |
the machine is not touched, except by a credential entry of secrets: another binding recreates the machine, and a new value of its secret restarts it, see secrets |
| create | from, template, branch |
used when the machine is created, never again: a change moves only the record |
The journal lists the change (“updating the machine in place: ports +3031:3030 -3030:3030, env +FOO”, “resizing the machine: cpus 4 → 8”) and state is updating meanwhile. Ports are compared by mapping (3000 and 3000:3000 are one), volumes and the allow list as sets, env by key; a reorder is no change. A failed resize or update makes the resource Error with the driver’s message and leaves the machine as that step left it (stopped after a failed update); the next apply or restart retries, and runy never recreates the machine instead.
A disk never shrinks: lowering storage or smolvm.overlay is an Error and nothing runs.
storage cannot shrink (60 → 40 GiB); smolvm disks only growThree changes cannot be made with smolvm’s machine update and count as identity changes: removing workdir, removing a volume that is a bare guest path, and removing a port while the same host and guest pair stays mapped for the other protocol. A cpus, memory, storage or smolvm.overlay removed from the spec keeps the machine’s value, with a note in the journal.
A driver may be unable to change labels or to report ports and mounts (smolvm does neither), so runy records what it last applied in the machine’s record in the daemon’s state database. For an existing machine it decides in this order: a record that describes the machine (same name, runy.spec label and creation time) compares its identity with the spec’s and diffs its settings against the spec; without one, a label equal to the hash of the whole current spec (a machine made by an earlier runy) is adopted and nothing runs; a label equal to the identity hash is adopted with a journal warning that the settings could not be verified; any other label is an identity change. The record is removed when the machine is deleted.
persistent
Section titled “persistent”Stop keeps the machine
Section titled “Stop keeps the machine”Only removing the document destroys the machine. runy stop vm/sandbox, disabling its namespace, stopping its parent, or an autorun: false resource that nothing references any more make the resource idle: the machine is stopped and kept with its disks and its record, without running the remove hooks. Starting the resource again (runy start, enabling the namespace) finds that machine and starts it. With an unchanged spec nothing is created and the create hooks do not run again, though the start hooks do; with a changed spec the stopped machine is updated in place. If the document is removed while the resource is idle, the daemon deletes the stopped machine (unless persistent) from what it recorded in the state database.
Stopping the daemon or a workspace stops the machine the same way, whatever persistent says, and the next start finds it. An in-place daemon upgrade does not stop it at all. A daemon that restarts while the resource is idle leaves the machine stopped.
Waiting for the VM
Section titled “Waiting for the VM”A dependent waits for the machine with needs:
kind: processname: probeneeds: - ${ vm.sandbox.status.state === "running" }spec: cmd: curl args: [-sf, "http://localhost:8080"]A dependent that needs the hooks done waits on ready, the machine’s default value (${ vm.sandbox.status.ready } in full):
kind: processname: buildneeds: - ${ vm.sandbox }spec: cmd: smolvm args: [machine, exec, --name, acme-sandbox, --, make]Hooks are lists of shell strings. Each runs inside the machine with sh -c, one after the other, through the driver (smolvm machine exec for smolvm), and its output goes to the resource’s journal. The spec’s workdir, user and env apply.
kind: vmname: sandboxspec: driver: smolvm image: alpine net: true hooks: create: - apk add git - git clone https://github.com/acme/app /workspace/app start: - git -C /workspace/app pull -q --ff-only remove: - echo byeThese variables are set for every hook, after the spec’s env:
| variable | value |
|---|---|
RUNY_MACHINE |
the driver’s machine name |
RUNY_RESOURCE |
the resource’s id, namespace/kind/name |
RUNY_WORKSPACE |
the workspace’s alias, not a path |
Create hooks run after the runy binary was copied in, when the machine was newly created or the record of a finished run inside it is missing or stale. That record is /var/lib/runy/hooks, holding a hash of the hooks, written once the create hooks pass; editing the hooks makes it stale, so they run again in place on the next apply. A machine that finished them and is started again skips them, and one whose hooks failed gets them again, after a daemon restart too. The setup signal always runs them again, see signals.
A failing create hook stops the sequence. The machine keeps running, ready is false and the resource is Error with “create hook N failed: …”; state is left alone. The journal numbers hooks from 1 in its messages, “running create hook N” and “create hook N failed: …” (the driver’s message or the exit status), and the failed hook is retried by the setup signal. Remove hooks run before the machine is deleted, only for a machine that is not persistent and is running when the resource is removed. A persistent machine is only stopped. Renaming machine removes the old machine with the old spec’s remove hooks. A failure is journaled and the removal goes on, and each hook is cut off after 60 seconds.
Start hooks
Section titled “Start hooks”hooks.start has the same shape as hooks.create and the same environment, but runs every time the machine starts, for work that has to be current each time: pulling a clone, mounting something, refreshing a cache. Start hooks run:
- after every start runy makes (a new machine, a started or restarted one, the start that ends an in-place update), once the
runybinary is in place and the create hooks have passed; while the create hooks are pending or failing, the start hooks wait; - on the
syncsignal, on a running machine, without a restart and without the create hooks; - after
setup, once the create hooks have run; - when the list changes while the machine runs, and while an earlier run has not passed;
- on a cold start that finds the machine running, when the list differs from the one that last passed. runy stores that list’s hash in the state database beside the machine’s record; a machine with no stored hash is taken as passed.
They run before sshd and before the link to the daemon inside is opened, so a guest daemon never starts its processes ahead of them. Write them to be idempotent. They do not run for a machine runy only adopts across a daemon upgrade, or finds already running after a daemon restart with an unchanged list. The journal numbers them from 1 (“running start hook N”) and tags their output lines with { "hook": "start", "index": N }. A failing start hook stops the sequence, leaves the machine running, sets ready to false and makes the resource Error with “start hook N failed: …”; sync runs them again. Adding or editing hooks.start never recreates or reboots the machine and does not make the create hooks run again.
runy inside the machine
Section titled “runy inside the machine”With runy: true, the default, runy copies a Linux build of itself for the machine’s architecture, which is the host’s (aarch64 or x86_64), to /usr/local/bin/runy after every start it makes, before the hooks. A script or an agent in the machine can then drive runy. Hooks can use it as well. The binary comes from the first of these that has it:
RUNY_GUEST_BINARIES, a folder holdingruny-linux-<arch>and optionally its.sha256. When it is set but lacks the file, the resource isErrorwithRUNY_GUEST_BINARIES (<dir>) has no runy-linux-<arch>, and runy tries nothing else.- The Bazel build, for a
runy-devdaemon: the guest binary is in the runfiles of the dev CLI. - For a released runy only: the release of the daemon’s own version, downloaded from
https://runy.dev/cli/<version>/runy-linux-<arch>, checked against its.sha256and cached in the daemon’s cache folder, asguest/<version>/, so it is fetched once per version.RUNY_RELEASES_URLreplaces the base URLhttps://runy.dev/cli, and setting it also lets a development build download.
A development build never downloads a release: it carries the version of the last release without being it. Without a guest binary it is Error:
this is a development build and its guest binary `runy-linux-<arch>` is not in <runfiles path>: run it through `runy-dev`, or `bazel build //products/runy/crates/cli:runy`Before a new binary replaces the installed one, runy runs it in the machine (daemon bridge --help with daemon: true, else --version). A binary that does not run is removed, the installed one and the link stay, and the resource is Error with the new runy binary does not run in machine <m>: <its output>. A sync looks for the binary again and retries.
When the release is not there (a 404 on the binary or its .sha256), the resource is Error:
no runy <version> release for linux/<arch> at runy.dev; set RUNY_GUEST_BINARIES to a folder with runy-linux-<arch>, or `runy: false`A binary whose checksum does not match its .sha256 is an Error too: <path or url> has sha256 <actual>, but its .sha256 says <expected>. runy never falls back to a release of another version. runy: false copies nothing.
The binary in the machine follows the hub. When the machine is running and the copy in it is not the one this hub resolves, runy copies the new one without stopping the machine and without the create hooks. That happens when a hub is upgraded while the VM keeps running, when a daemon cold start finds the machine running, and on the sync and setup signals. The journal says runy in the machine: <old sha> → <new sha>; relinking, and with daemon: true the link is closed and opened again, so the new bridge upgrades the daemon inside in place and the processes it runs keep running. A failed copy makes the resource Error and keeps the old link.
A port resource can pick the host side of a mapping:
kind: portname: web---kind: vmname: sandboxspec: driver: smolvm image: nginx net: true ports: ["${ port.web }:80"]Another resource reads the mapping back as ${ vm.sandbox.status.ports[0].host }.
When the ports belong to the machine, declare them as children and read them as child.port.<name>. They are wanted with the machine and go idle with it:
kind: vmname: sandboxchildren: - { kind: port, name: web, spec: { preferred: 3030 } }spec: driver: smolvm image: nginx net: true ports: ["${ child.port.web }:80"]The port is the resource port/sandbox.web, and the mapping is served as web.sandbox.vm.runy.localhost, see names in the proxy.
Names in the proxy
Section titled “Names in the proxy”Every tcp mapping of the machine is routed by the daemon’s proxy as <name>.<host>.vm.runy.localhost, an HTTP route (with :<proxy port> appended unless the proxy listens on 80). The exception is a mapping to guest port 22, which is ssh.<host>.vm.runy.localhost, a TCP route that only answers CONNECT (sshd has no use for an HTTP name).
<host> is the resource’s name, or <namespace>-<name> for a resource inside a namespace; setting machine does not change it. <name> comes from the mapping:
- A mapping whose host port comes from a port resource of the same workspace and namespace is named after that port. A child port is named by its own name, so
port/sandbox.notesgivesnotes.sandbox.vm.runy.localhost, and another port of the namespace by its name. - A mapping with a literal host port is named by its guest port:
8080:8080gives8080.sandbox.vm.runy.localhost. - A name that is not one DNS label, is
ssh, or was already taken by an earlier mapping of the machine falls back to the guest port.
kind: vmname: sandboxchildren: - { kind: port, name: ssh } - { kind: port, name: notes }spec: driver: smolvm image: debian:bookworm-slim net: true ports: - ${ child.port.ssh }:22 # ssh.sandbox.vm.runy.localhost - ${ child.port.notes }:3030 # notes.sandbox.vm.runy.localhost - 8080:8080 # 8080.sandbox.vm.runy.localhostThe status carries the name in ports[].name, next to domain and url. The names follow the port resources: when a daemon is upgraded, or a port moves to another value, the domains are renamed without touching the machine. If two workspaces declare the same host, the first one holds it and the second reports an error. The names need no configuration; a port resource’s own domains keep working beside them.
The routes exist as soon as runy knows the machine, running or not: a stopped machine answers with the 502 page naming the resource. They are released when the resource stops or is removed and when the daemon stops. A host that another resource holds makes the resource Error with the same message as a port domain conflict, and nothing of this resource is routed.
ssh: true or ssh: { user, keys } makes the machine reachable over ssh. It needs a mapping to guest port 22 or daemon: true, or the resource is Error:
ssh: map a host port to guest 22, e.g. `${ port.ssh }:22`, or set `daemon: true` to reach it through the linkWith daemon: true and no mapping to guest 22, sshd is reached through the link as ssh.<machine>.runy.localhost, or ssh.<machine>.<host>.runy.localhost with the hub’s host label (the name a mesh peer always reaches it by), and status.ssh.port is null.
| field | default | |
|---|---|---|
user |
the guest login | the spec’s user when it is a name, else root |
keys |
public keys: a key string, or a path relative to the workspace (~ is expanded) |
every ~/.ssh/*.pub of the daemon’s user |
Without keys and without a .pub file the resource is Error: ssh: no public keys in ~/.ssh (*.pub); set ssh.keys.
After every start runy writes the keys to authorized_keys in the user’s home (found with getent passwd, .ssh created with mode 700, the file copied with mode 600). After the create and start hooks pass, on every boot and on setup too, it checks for /usr/sbin/sshd, runs ssh-keygen -A for missing host keys and starts sshd detached, unless it already runs. sshd is not installed by runy; without it the resource is Error and ready is false:
ssh: /usr/sbin/sshd is not in the machine; install openssh-server in hooks.createready is true only once sshd was started as well, and the status carries ssh.command, for instance ssh [email protected], or ssh [email protected] through the link.
Walkthrough
Section titled “Walkthrough”kind: portname: ssh---kind: portname: web---kind: vmname: sandboxspec: driver: smolvm image: debian:bookworm-slim net: true ssh: true ports: - ${ port.ssh }:22 - ${ port.web }:3000 hooks: create: - apt-get update && apt-get install -y openssh-server*.localhost resolves to the loopback by itself, so ssh needs the proxy in between. Add the stanza to your ssh config once; it covers every machine:
runy ssh-config >> ~/.ssh/configThen connect with the name from ssh.command:
The stanza is described under runy ssh-config. The guest’s port 3000 is http://web.acme-sandbox.vm.runy.localhost in a browser, named after the web port.
daemon
Section titled “daemon”daemon: true makes the machine a machine of the hub: once it is running and the binary, the create hooks and the start hooks are done, the hub links to the runy daemon inside it (through the driver’s stdio exec, smolvm machine exec -i for smolvm, no ssh needed), and runy apply -m acme-sandbox and the others reach it by the machine’s name. It needs runy: true, or the resource is Error.
kind: vmname: sandboxspec: driver: smolvm image: debian:bookworm-slim net: true workdir: /work/app daemon: trueworkspaces lists the paths registered as workspaces on that daemon on every connect; the first is the default one. It defaults to [workdir]. status.daemon.state is the link’s state (connecting, connected, disconnected, incompatible), with version and reason.
The status carries routes: [{ domain, protocol, resource, url }] for the names the proxy routes into the machine, see routes.
The binary is copied next to the old one and moved over it, so a daemon already running keeps working until the link restarts it. runy prepares the machine in a fixed order: the binary copy, the create hooks, the start hooks, the ssh keys and sshd, then the link. The guest daemon follows the hub’s build (see runy inside the machine). restart and setup close the link first and open it again after, and it closes with the machine when the machine stops. The machine’s workspaces show nested in the console, where each resource inside has its own Output; this resource’s journal has only its own lines.
routes
Section titled “routes”With daemon: true, the hub’s proxy can serve the port resources the daemon inside the machine runs, with no ports: mapping and no host port. routes selects them: absent or true routes all, false routes none, and a list of <namespace>/<port> globs routes those that match (* matches any run of characters, ? one; _ is the top level).
kind: vmname: sandboxspec: driver: smolvm image: debian:bookworm-slim net: true ssh: true daemon: true routes: ["notes/*", "_/console"]A running port web of namespace notes in the workspace app-9xk2p7qd of the machine acme-sandbox, on a hub whose host label is mini, is then web.notes.app-9xk2p7qd.acme-sandbox.mini.runy.localhost, the full name that always works. It is also web.notes.app-9xk2p7qd.acme-sandbox.runy.localhost without the host label, and web.notes.app.acme-sandbox.runy.localhost (with or without mini) by the workspace’s folder. A top-level port console is console.app-9xk2p7qd.acme-sandbox.mini.runy.localhost, and console.app.acme-sandbox.runy.localhost for short. The status lists the shortest name that is routed. The machine may not be named like the hub’s host label or a mesh peer’s. The guest server may listen on its loopback. Without daemon: true an absent routes routes nothing, and an explicit true or list makes the resource Error (routes needs daemon: true). Changing it does not touch the machine or the link. Names, limits and what the hub checks are in machine routes.
Mappings in ports: and their vm.runy.localhost names are unchanged and still serve a real host port.
Metrics
Section titled “Metrics”While the machine runs, runy samples its CPU, memory and disk usage and writes each sample to the resource’s own journal, on the daemon that holds the resource. The first sample is taken once the machine is up, then one every interval seconds (60 by default), whether or not anyone is looking. Sampling stops with the machine (stop, idle, an in-place update that stops it, removal) and resumes when it starts again.
kind: vmname: sandboxspec: driver: smolvm image: alpine metrics: { interval: 30 } # or false to turn sampling off journal: { max_lines: 10000 }The smolvm driver reads CPU and memory with smolvm machine stats --json and the root filesystem with df -B1 -P / inside the machine. A part that cannot be read is left out of the sample; a sample with nothing in it is not written, and three failed samples in a row are one warning in the journal.
Each sample is an info line whose message reads cpu 4.9% · mem 4.0/15.6 GiB · disk 12.3/60.0 GiB and whose fields hold the numbers, so stream: metrics in the journal’s filter shows the history:
{ "stream": "metrics", "cpu_percent": 4.87, "cpus": 8, "memory_used": 4294967296, "memory_total": 16750000000, "memory_available": 11811160064, "disk_used": 13207470080, "disk_total": 64424509440 }cpu_percent is what the driver reports. The samples share the journal’s cap with the other lines, so raise journal.max_lines for a longer history; at the default 5000 lines and interval a quiet machine keeps about three days. The GetResourceMetrics rpc returns the stored samples, the last 1440 at most, and the console’s Overview draws them. Changing metrics or journal does not touch the machine.
Egress
Section titled “Egress”egress limits what the guest may reach on the network. Without it the machine reaches what net allows: everything with net: true, nothing with net: false.
kind: vmname: sandboxspec: driver: smolvm image: alpine egress: allow: [github.com, "*.npmjs.org", 10.0.0.0/8, "2606:4700::/32"] deny: [169.254.0.0/16] block_private: true| field | smolvm | |
|---|---|---|
allow |
when present, the machine reaches only what it lists; each entry is a hostname, a *.domain pattern, a CIDR or an IP address |
--allow-host, --allow-host-pattern, --allow-cidr |
deny |
CIDRs or IP addresses the machine never reaches, checked before anything is allowed | --deny-cidr |
block_private |
true: private, internal and link-local destinations are refused (the LAN, cloud metadata, CGNAT, the host’s loopback), while the public internet stays open |
--block-private |
Each allow entry is read strictly. A hostname (github.com) allows the name and its subdomains. A pattern (*.npmjs.org) allows the subdomains of the domain, and * is allowed only as a leading *.. A CIDR is address/prefix, IPv4 or IPv6, and a bare address is the one address (/32 or /128). Anything else is a spec error naming the entry, such as egress.allow[1] (https://github.com`): a URL: name the host alone: a URL, a port (github.com:443), a wildcard elsewhere, an empty entry. deny` takes CIDRs and addresses only.
egress turns the network on, so net may be left out, and egress with net: false is an error. allow: [] allows nothing but the hosts of the machine’s credentials; smolvm reads an allow list with no entries as no list, so for an empty one the driver passes the one entry 192.0.2.0/32, an address of a documentation range that nothing routes.
What smolvm does with the policy:
- Hostnames are resolved when the machine starts. A name whose addresses change while it runs is reached at the addresses it had then; a restart resolves it again.
- A name that is not allowed fails to resolve in the guest (NXDOMAIN), and a connection to an address that is not allowed is refused.
- DNS itself is not restricted: the guest may resolve any name, and only the answer for a name the policy refuses is empty.
Credentials. When allow is present, the hosts of every credential entry of secrets (the secret’s inject.hosts) are added to it as hostnames, so a credential always reaches its hosts. Without allow nothing is added.
Changes. A changed allow is applied to the stopped machine: stop, one smolvm machine update --reset-allow-list with the whole new list, start. Removing allow resets the list and opens the network again (--reset-allow-list --net). smolvm machine update has no flag for --deny-cidr or --block-private, so a changed deny or block_private recreates the machine, and is an Error with persistent: true. Adding or removing the whole egress key follows the same rules for each part. The machine’s record keeps the policy as it was applied, credential hosts included, so a daemon restart plans from it.
Refusals. While the machine runs, the daemon reads what the policy refused (smolvm machine egress-events --json) every 5 seconds, together with the status, and only for a machine with a policy. Each new refusal is a warning in the resource’s journal, one line per destination and read with its count, and the fields { "stream": "egress", "operation", "dest", "count" }, so stream: egress in the journal’s filter lists them:
egress refused: connect 1.1.1.1:80egress refused: resolve example.com (4 times)operation is resolve for a name and connect for an address and port. status.egress is { refused, recent }: refused counts the refusals this daemon read since the machine last started (a daemon restart or upgrade starts it at 0), and recent lists the 20 latest distinct ones, newest first, as { at, operation, dest, count } (at the latest time, count since the start). smolvm keeps the newest 200 refusals and stamps them to the second, and a resolver retries a refused name, so runy tells a new refusal from one it read by its time and by how many of that second it took before; more than 200 refusals between two reads lose the oldest, and none is counted twice. Refusals from before a start, or from while the daemon was down, are not journaled. A failing read is one warning in the journal until a read passes, and never stops the machine.
A template may set egress too: its builder machine gets the policy (without credential hosts, as it has no credentials), and its instances inherit it. An instance’s own egress replaces the template’s whole key.
A driver that cannot enforce a policy reports egress as an Error naming the driver.
Secrets
Section titled “Secrets”A machine gets no secret unless its spec lists it. secrets is a list of entries, each naming a secret and how the machine may use it (Secrets in machines compares the ways):
kind: vmname: sandboxspec: driver: smolvm image: alpine secrets: - secret: ${ secret.github } credential: GITHUB_TOKEN - secret: ${ ns.notes.secret.db } resource: true - secret: ${ secret.anthropic } proxy: true| field | |
|---|---|
secret |
an expression naming the secret, ${ secret.<name> } or ${ ns.<namespace>.secret.<name> }; a plain name is an error |
credential |
a variable the guest gets; the driver puts the value on the guest’s HTTPS requests to the secret’s inject.hosts |
resource |
true: resources in the machine may use the secret; the runy daemon inside reads the value from this daemon |
proxy |
true: processes in the machine may send requests through this daemon’s gateway for the secret |
An entry needs at least one of credential, resource and proxy, and they combine. A secret may appear in one entry only. The vm waits until every secret it names has a value, and an unknown secret is an Error. These are the vm’s errors, naming the entry (secrets[1] (...)): an entry with no flag, a secret named by two entries, a secret that is not exactly one placeholder (a name string, text around it, two of them), a credential that is not a variable name or is also a key of env or of another entry, two secrets with the same credential name, and credential or proxy on a secret that has no inject. A driver that cannot substitute credentials reports a credential entry as an error.
Only credential entries touch the machine: a changed binding recreates it (an Error with persistent: true), and a rotated value or a changed value format restarts it. A change to proxy or resource is applied in place.
What each flag allows, the driver’s limits and the journal lines are in Secrets in machines.
A template may list secrets too: its instances inherit them and may add their own, and the template’s builder machine never gets any.
Signals
Section titled “Signals”restart stops and starts the machine; it does not recreate it, and the create hooks do not run again (the start hooks do). stop stops the machine through the driver, and the next poll publishes stopped. setup runs the create hooks again, then the start hooks, for instance after fixing a failing hook. sync runs the start hooks on a running machine, without a restart, without the create hooks and without touching the daemon link; it also copies the runy binary if it differs. setup and sync need a running machine (“machine x is not running” otherwise) and, like restart and stop, wait for a running ensure:
runy signal acme/vm/sandbox setupruny signal acme/vm/sandbox syncpack writes a pack of the machine, see a machine from a pack:
runy signal acme/vm/sandbox packOther signals are ignored.
A machine from a pack
Section titled “A machine from a pack”from creates the machine from a pack of another machine (smolvm: a .smolmachine, passed to smolvm machine create --from) instead of an image. A relative path is resolved against the workspace folder. It is exclusive with image, cmd and smolvm.smolfile, and only a driver that can pack accepts it; smolvm can. The new machine starts with the packed machine’s whole disk: its tools, checkout, build outputs, the runy binary and the daemon’s loaded sources and enabled namespaces. With daemon: true it starts the same stacks. It is its own machine, with its own name, hostname, labels, ports, link and routes (<port>.<namespace>.<workspace>.<machine>.<host>.runy.localhost, see machines).
kind: vmname: taskspec: driver: smolvm from: packs/sandbox.smolmachine daemon: truefrom is read when the machine is created. Changing it, or writing a new pack to the same path, never recreates or updates a machine that exists. The journal says from changed to PATH: machine x keeps its disk; delete it to have it created from the new pack, and the machine’s record notes the pack the machine was created from. A file that does not exist is an Error (from: there is no pack at PATH).
The marker on the machine’s disk (/var/lib/runy/hooks, see hooks) decides the create hooks. Hooks equal to the packed machine’s do not run and different ones all run, so a machine from a pack usually declares no create hooks and uses start hooks.
The first time the machine starts, runy removes what it must not share with the packed machine: the guest daemon’s mesh identity, pid file and logs, and with ssh: true sshd’s host keys, which are generated again. It writes the machine’s name to /var/lib/runy/machine in the guest, so this runs once.
pack names the file the pack signal writes. The signal syncs the guest’s disks, stops the machine, runs smolvm pack create --from-vm, moves the pack into place and starts the machine again with its link; a machine that was stopped is packed and left stopped. state is packing meanwhile and status.pack holds the result afterwards. A failed pack keeps the previous file, starts the machine again and is an Error on the resource, and the signal on a vm without pack is an error from the signal. Changing pack alone does not restart anything. The two keys are tied by a path because a reference to the other vm’s status would make the reader depend on the packed machine and start it.
Packing may run 30 minutes and creating from a pack 10, since the first machine from a new pack extracts it; other smolvm commands keep 60 seconds. smolvm pack prune removes extractions that no machine refers to.
Instances of a template
Section titled “Instances of a template”A vm with template is created from the current build of a template instead of an image. The value is the template’s name, or <namespace>/<name> for a template of another namespace.
kind: vmname: task-42spec: template: sandbox env: { TASK_REF: feature/x } memory: 4096An instance inherits the template’s spec: its driver options, cpus, memory, net, ports, volumes, env, workdir, hooks.start and hooks.remove, runy, ssh, daemon, workspaces, routes, metrics, journal and secrets. It does not inherit what only the build used: image, cmd, user, stop_timeout, smolvm.smolfile, hooks.create and the build, refresh and stamp steps, since the machine runs the disk the build left, so it runs no create hooks. The template’s children are cloned under the instance, so each instance has its own ports.
An instance sets only memory, cpus, routes, metrics, journal, persistent, machine, env, secrets, egress and branchable; env is merged over the template’s key by key, secrets entry by entry (an instance’s entry for a secret replaces the template’s entry for it), and the others replace (an instance’s egress replaces the template’s whole policy). Any other key is ignored with a diagnostic naming it. The instance is Pending until the template has a build, and its status has template: { id, build, stamp }, naming the build it was created from.
A new build never touches an instance that exists: the machine keeps its disk, and only vms created afterwards use the new build. Edits to the template that apply to a running vm, such as ports or hooks.start, are applied to its instances in place. Pass parameters as env values and read them in hooks.start, which runs on every start.
runy vm run applies such a document and runy vm rm deletes it:
runy vm run sandbox --name task-42 -e TASK_REF=feature/x --memory 4096 --cpus 2 --waitruny vm rm task-42run takes the template as <name>, <namespace>/<name> or template/<name>, -e KEY=VALUE (repeatable), --memory in MiB, --cpus, -n <namespace> for the vm’s namespace (default the top level) and --wait, which waits until the vm is ready and fails when it fails or when the vm is idle. rm takes one or more names, as runy delete vm/<name> does. Instances made this way are applied documents.
Branches
Section titled “Branches”A branch is a second machine made from a running one in about half a second. smolvm copies the source’s memory and disks copy-on-write, so the processes that ran in the source keep running in the branch: a stack that took minutes to start (a dev server with its caches warm, a database with its data loaded, a long build half done) gets a second copy without booting or provisioning again. Try a change in the branch and throw it away, or run two tasks from the same starting point.
The source runs with branchable: true, which starts its machine as a branch source (smolvm machine start --branchable, which backs guest memory so it can be copied and opens a control socket). It applies at a start, so changing it stops the machine and starts it again with or without the flag. status.branchable is true while the machine runs and runy last started it with the flag. runy keeps that fact in the machine’s record and does not ask smolvm, whose machine status reports branchable: false for such a machine too. A daemon restart or upgrade keeps it, and a machine runy finds running without it (one adopted, or started by an older runy) is stopped and started once with the flag.
kind: vmname: sandboxchildren: - { kind: port, name: web, spec: { range: [3000, 3099] } }spec: driver: smolvm image: debian:bookworm-slim branchable: true ports: ["${ child.port.web }:3000"] hooks: start: ["/work/app/serve &"]---kind: vmname: try-fixspec: branch: sandbox env: { FEATURE: fix }A vm with branch is made by branching that vm. The value is the source’s name, or <namespace>/<name> for a vm of another namespace. It is exclusive with image, from, template, cmd and smolvm.smolfile, and a source without branchable: true is an Error (“vm ns/sandbox is not a branch source: set branchable: true on it”). The branch takes the source’s spec the way an instance takes its template’s (for a source that is itself an instance, the spec it was expanded to) without image, cmd, user, stop_timeout, machine, persistent, pack, branchable and hooks.create, and it sets the keys an instance sets: memory, cpus, routes, metrics, journal, persistent, machine, env (merged key by key), secrets (merged by secret), egress and branchable. Its own branchable: true makes it a branch source in turn, so a branch of a branch works. The source’s children are cloned under the branch, so the branch has its own port resources and its own names in the proxy.
The branch is Pending (“waiting for vm/sandbox to run as a branch source”) until the source runs as a branch source. Then runy runs smolvm machine branch --from <source machine> --name <machine> --no-wait-ready with the branch’s own labels, -e for each variable the branch sets over the source’s, -p for each of its mappings (its own ports, pinned) and --branchable when its own spec has it. Its create hooks do not run, since the disk and the processes come from the source; its start hooks run, as after every start. cpus, memory, storage or smolvm.overlay larger than the source’s are applied after the branch with smolvm machine resize. Any other setting that differs from what the source’s machine has (a smaller size, volumes, net, egress) is an Error on the branch before anything runs, naming the key: smolvm’s branch takes none of them.
The source’s guest daemon keeps running in the branch. Before the runy binary, the hooks and the daemon link, runy removes the guest daemon’s mesh identity from its disk and the copied hub.sock, and writes the branch’s machine name to /var/lib/runy/machine. The guest daemon’s processes, workspaces and logs, and sshd with its host keys, stay, and the link reaches the guest daemon under the branch’s own machine name and routes. When the branch’s secrets are not the source’s, runy also stops the guest daemon, which holds in memory what the hub granted the source; the link starts it again and it asks the hub anew, so its processes start again too. A branch with credential entries gets their values in the environment of machine branch, as a start does.
A branch’s identity does not include its source: a later change to the source reaches the branch like any change to its spec and never branches it again. A branch is branched again when its own identity changes (its machine, a credential binding) or its machine is gone, from the source as it is at that moment, and what the old branch had is lost. While the source does not run as a branch source, such a branch waits as it did at first. A running branch whose source stops shows Pending with that message and keeps running.
A source cannot be deleted while branches of it exist. When the source’s document is removed and branch documents remain, the source’s resource stays, running, with the Error “vm/try-fix was branched from it: remove them first”, and is removed once the branches are gone. Removing a source and its branches together removes the branches first. runy stop of a source with running branches leaves it running, as for any vm another resource reads.
runy vm branch sandbox --name try-fix -e FEATURE=fix --waitruny vm rm try-fixruny vm branch applies the document above and fails at once when the source is not a branch source. It takes the source as <name>, <namespace>/<name> or vm/<name>, -e KEY=VALUE (repeatable), --memory and --cpus (larger than the source’s), -n <namespace> and --wait, like runy vm run.
Limits:
- A mapping with a literal host port collides with the source’s own; give the source’s ports
portchildren, which a branch clones. - A smaller size, other volumes, another
netoregresscannot be given to a new branch; change the source first, or change the branch after it is made (a stop and an update, which ends its processes). - A persistent branch keeps its machine when its document is removed, and the source’s machine then cannot be deleted either: the source’s journal says so, and both machines are removed by hand.
- The branch’s memory and disks are shared with the source until either side writes, so a branch costs little at first and grows as it diverges.
- A source kept for its branches after its document was removed is kept by the running daemon only: after a daemon restart its machine stays, stopped, and is removed by hand.
Install the smolvm binary
Section titled “Install the smolvm binary”brew install smol-machines/tap/smolvmcurl -sSL https://smolmachines.com/install.sh | bash
