Environments
The VM lifecycle: one microVM and the task running inside it
An environment is a single microVM and the task running inside it. You create one with a resource spec (CPU/memory/storage, and optionally GPU), an optional manifest and secrets, and an optional startup script. Fuse picks a host, boots the VM, uploads your files, starts the in-guest agent, and tracks it through its lifecycle. A background reconcile loop catches orphans and stuck VMs.
Lifecycle states
provisioning -> running -> draining -> destroying -> destroyed
-> failed
destroying -> destroy_failed -> destroying (on DELETE)
- provisioning: a host has been picked and the VM is booting.
- running: the VM is up and the in-guest agent is reachable.
- draining: a graceful two-phase teardown has started: the agent’s drain command has been invoked so the workload can flush/stop cleanly, but the VM is not yet destroyed. Only running environments can be drained; any other state returns a conflict.
- destroying / destroyed: the VM is being (or has been) torn down.
- destroy_failed: a destroy whose host kept failing after every retry. The VM may still exist on
its host and still counts against the host’s capacity. The last error is on
the environment and in a
destroydead letter.DELETEit again to retry. - failed: provisioning or an operation failed.
destroyed and failed are terminal states you only ever observe on the event
stream: by the time either is published the environment record has already been
removed, so a follow-up fuse environment get <id> returns 404 rather than a record
carrying the failure. The error text survives on the task record, and --follow (or
fuse environment watch) prints it inline, so read it there rather than expecting it
on the environment.
Drain itself does not destroy the VM. A subsequent explicit destroy call removes
it. If none arrives, a durable timer the drain arms destroys an environment that
has been draining longer than the draining timeout, 5m30s by default
(--draining-timeout on the orchestrator), and survives an orchestrator restart
(stuck draining).
Health is not a state
running means the VM is up and the guest agent is reachable. It does not mean
your workload is serving: nothing dials it.
An environment created with a healthcheck
carries a separate health field, whose state is starting, passing, or
failing. It is deliberately not folded into the lifecycle vocabulary above: that
set is closed and every SDK reasons about it, and an unhealthy environment is
still a running one.
Nothing is destroyed for a failing probe. The field reports, and
fuse up --wait-healthy is what turns
it into a gate. An environment that declared no healthcheck never carries the
field at all.
Creating one
Two paths: compile a Fusefile with fuse up, or
create one directly with a raw resource spec:
fuse environment create --task-id my-task --cpus 2 --ram-mb 2048 --storage-gb 10
create schedules orchestrator-wide. The CLI’s active host selection does not pin
placement; use --region to influence it.
Watching progress
fuse environment watch <id> # stream state transitions until terminal
fuse environment create --follow ... # same, inline with create
Both are backed by the same mechanism as the HTTP API’s live event stream (Server-Sent Events), no polling loop involved.
Draining and destroying
fuse environment drain <id> # running -> draining (graceful, phase 1)
fuse environment destroy <id> # tear down (phase 2, or from any state)
Long operations and retries
Create, destroy, fork, migrate, drain, snapshot create, snapshot restore and
image convert run on the orchestrator as operations, off the request that
started them.
The request waits for its operation up to the server’s attach bound, 10
seconds below its -write-timeout (50s by default), and answers as it always
has when the operation finishes in time. One that takes longer, a cold boot
with a slow startup script or a cross-host migrate, is answered 202 with an
operation id instead, and keeps running. ?wait=false asks for the 202 at
once, and ?wait=30s waits that long (capped at the bound). Every answer an
operation gives carries its id in a Fuse-Operation-Id header.
The SDKs and the CLI follow a 202 for you, polling
GET /v1/operations/{operationId} until the operation
finishes, so a long call simply takes longer to return. Leaving early (a
cancelled context, an interrupted CLI) leaves the operation running; pick it
up with fuse operation wait or the SDKs’
operations.wait. Every operation runs on
restate, so its step stays empty;
a migrate’s steps show in the restate ui and in
orchestrator_step_duration_seconds{op="migrate_live"} instead.
An Idempotency-Key header makes a mutating call safe to retry. A retry of
the same request with the same key attaches to the first call’s operation
instead of running again, waiting for it if it is still running or replaying
its answer (with Idempotent-Replayed: true) if it finished. That is what
turns “the connection dropped during a create” from a guess into a second
call that cannot provision a second environment. The rules:
- Keys are scoped to the credential that sent them, 1 to 255 visible ascii characters.
- The same key with a different request is a
409conflict,details.reasonidempotency_key_reused. - A finished operation and its key are kept for 24 hours. One that finished with a 5xx is not kept, so its retry runs again. A failure restate recorded reruns as a new restate invocation; one from before restate answered (a timeout, a dropped connection) attaches to the first invocation.
- Operations and keys live in the orchestrator’s memory, and a restart forgets
them. Every operation also hands the key to restate as its invocation’s
idempotency key, so a retry after a restart still attaches to the same
invocation. A destroy or migrate that already finished is the exception: the
vm it acted on is gone, so that retry answers
404. After a restart, a key whose earlier try failed with a 5xx may replay that failure for up to restate’s idempotency retention (24 hours); retry with a fresh key.
The SDKs send a random key on every call and take your own for retries:
WithIdempotencyKey in Go, idempotencyKey in
TypeScript and idempotency_key in
Python. The CLI sends a fresh key on every
invocation, so running a command again is a new request, not a retry of the
last one.
Forking
fuse environment fork <id> --comment "branch for experiment"
Forking creates new environments from an existing one’s state, either by taking a
fresh snapshot or reusing an existing one via --reuse-snapshot. The source keeps
running and is not modified.
--count N makes N children from that one seed. The seed is taken once, and each
child is its own fork: one that fails does not undo its siblings. The answer is
always a list, 201 with {"children": [...]} even for one child, and the SDKs’
Fork returns that list. If any child fails, the call returns the first
failure’s status. Its message names the children that did fork, and those keep
running. Children’s IDs come from the request’s Idempotency-Key, so retrying
with the same key and count gets you the same children back.
The fork is a full environment of its own: its own ID, its own IP and ports, and its own guest credentials. Because it boots a copy of the source’s disk, it starts out with the source’s filesystem contents, but it is re-issued a fresh auth token on creation, so the two environments never share a secret.
The source must be running; forking an environment in any other state fails.
A fork lands on the same host as its source when that host has room for it
(the seed snapshot already lives on that host’s disk), and it is charged against
that host’s capacity like any other environment. When the source’s host is full,
the scheduler places the fork on another host of the same backend and copies the
seed snapshot there, as long as the snapshot can be copied. When no host has room,
the fork is refused with 503 unavailable and a Retry-After, and nothing is
created; the CLI and the SDKs retry it a few times before giving up.
A plain fork cold-boots the snapshot’s disk rather than resuming the source’s
memory, so expect a normal boot, not a sub-second resume. It refuses a
live snapshot with 409, because a live
snapshot’s disk is only consistent alongside its memory image.
fuse environment fork <id> --live --count 10
--live forks from memory instead. It takes a live seed (or reuses the live
snapshot named by --reuse-snapshot), and every child resumes from that memory
image with its processes intact. A live child cannot resume on its source’s own
host yet, so it always lands on another host of the same backend, with the same
CPU model and Firecracker build, and the seed’s memory image is copied there.
With no other host that can take it, the fork is refused with 409 conflict.
See Snapshots: forking is unavailable wherever snapshotting is (i.e. QEMU/GPU environments).
Rotating guest credentials
fuse environment rotate-token <id>
Generates fresh TLS credentials and an auth token for a running environment, writes them into the guest’s credential files, and persists the new encrypted token on the orchestrator, all without recreating the VM.
Rotation requires the environment to be running. The new token is sealed with
the orchestrator’s TOKEN_ENCRYPTION_KEY, which every orchestrator now starts with.
Rotation takes effect in the running guest: after the files are written the
orchestrator sends fused a SIGHUP, and it rereads its token and TLS certificate
in place. The token is checked when a request starts, so new requests with the old
token are refused, but a request already in progress (an open
/v1/computer/stream, for example) keeps running until it ends. Connections already
open keep the old certificate until they reconnect.