Two surfaces trigger work in this system and nothing else does: a CLI invocation, dispatched
through a 17-arm exhaustive match (microvms-cli/src/main.rs:382-403), and a daemon HTTP
request, dispatched through a handler table walked from the same list /v1/schema publishes
(agentd/src/routes.rs:110). The bindings re-enter the same microvms-core surfaces the CLI
uses, so they add no distinct flow, and the daemon’s only recurring job is a 30-second
expired-exec reaper rather than a request lifecycle (agentd/src/main.rs:61,
agentd/src/exec.rs:951).
The three flows below are ranked by how much of the client-to-daemon boundary each exercises, tie-broken by whether it is named after one of the system’s core verbs. Flow 1 is the only arm that launches a VM and the only one that touches all four actors. Flow 2 is the streaming read path, whose correctness rests on a byte-offset cursor that survives a reconnect through the endpoint proxy. Flow 3 is the file-transfer path, and it ends in the daemon’s one confined write.
Participants are the workspace crates named in architecture/module-map.md plus two external
actors. microvm CLI is microvms-cli; agentd is the in-VM daemon; AWS MicroVMs is the
control plane together with its endpoint proxy.
Flow 1: microvm run — build, launch, bootstrap, exec, tear down
Section titled “Flow 1: microvm run — build, launch, bootstrap, exec, tear down”commands::lifecycle::runresolves region, size class, and image name, then requires every infra role before anything is created, so a missing role surfaces immediately rather than after a build (microvms-cli/src/commands/lifecycle.rs:121, guard atmicrovms-cli/src/commands/lifecycle.rs:141-166).- It opens a
Sandboxthrough the library seam and raceslaunch_and_execagainst ctrl-c in atokio::select!, with the sandbox owned outside the select so a cancelled launch still holds the identifiers teardown needs (microvms-cli/src/commands/lifecycle.rs:170-198, recovery atmicrovms-cli/src/commands/lifecycle.rs:213-220). launch_and_execpreflights the build request, uploads the artifact, thenSandbox::build_imageissuesCreateMicrovmImageand waits for the image to become usable (microvms-cli/src/commands/lifecycle.rs:302-307,microvms-core/src/sandbox.rs:551).Sandbox::runrefuses a second bootstrap on the same sandbox, mints the agent token, and wraps it with the launch env in a typedRunHookPayloadthat checks its 4096-byte budget before any call (microvms-core/src/sandbox.rs:648, refusal atmicrovms-core/src/sandbox.rs:652, payload atmicrovms-core/src/sandbox.rs:682).ControlPlane::run_microvmvalidates the identifier, the duration range, and the role ARN, splits ingress and egress connectors by intent, and puts the payload on the wire (microvms-core/src/control/microvm.rs:356).- The platform calls the daemon’s run hook over loopback;
run_hookunwraps the envelope, parses the inner payload, and installs the token once — an identical replay is 200 and a different token is 409 (agentd/src/routes.rs:178, verdicts atagentd/src/routes.rs:213-234). ControlPlane::wait_for_runningpolls to RUNNING and fails fast on any terminal state; the client then polls unauthenticated/v1/healthuntilbootstrapped(microvms-core/src/control/microvm.rs:435,microvms-core/src/session/mod.rs:342). The sandbox marks the token installed only after RUNNING is observed (microvms-core/src/sandbox.rs:722-724).- The optional workload runs through
Session::run_sync— start, wait, ack — andtear_downplusattach_costthen run however the select ended (microvms-core/src/session/mod.rs:408,microvms-cli/src/commands/lifecycle.rs:393,microvms-cli/src/commands/lifecycle.rs:443).
Flow 2: microvm exec –stream — SSE output on a byte-offset cursor
Section titled “Flow 2: microvm exec –stream — SSE output on a byte-offset cursor”commands::attached::execattaches a session from the identifier triple, builds the start request under a caller-supplied or mintedexec_id, starts the command, then branches tostream_exec(microvms-cli/src/commands/attached.rs:103, branch atmicrovms-cli/src/commands/attached.rs:163-165).stream_execdrivesExecHandle::for_each_eventwith aFnMut(ExecEvent) -> ControlFlow<()>callback, writes one NDJSON line plus the raw bytes per event, and reportsnextOffsetfrom core’s cursor rather than its own tally (microvms-cli/src/commands/attached.rs:240, cursor read atmicrovms-cli/src/commands/attached.rs:281).for_each_eventdelegates tofor_each_event_async, whose loop steps theadvancestate machine, reads the cursor off the machine, and reportsEndReason::Cutwhen a body ends with noexitevent (microvms-core/src/session/exec.rs:347, loop atmicrovms-core/src/session/exec.rs:419-428).advancere-attaches at the last good cursor with a fixed backoff on a retryable failure, and errors out pastmax_reconnectsinstead of looping forever (microvms-core/src/session/exec.rs:460, backoff and re-attach atmicrovms-core/src/session/exec.rs:487-491).ExecHandle::attachissuesGET /v1/exec/{id}/stream?offset=Nwithaccept: text/event-stream, building its headers inside the request path so a mid-stream reconnect re-mints an expired token (microvms-core/src/session/exec.rs:591, mint atmicrovms-core/src/session/exec.rs:600).ProxyAuth::headersserves the cached proxy token, or takes the mint lock and re-checks freshness under it so two racing tasks do not burn two control-plane calls (microvms-core/src/session/proxy.rs:432, double check atmicrovms-core/src/session/proxy.rs:521-530).- The daemon’s
streamhandler snapshots the replay ring, reads the terminal marker after the snapshot, and sends the SSE body with a keepalive plusx-accel-buffering: noso a buffering proxy cannot batch a live stream into one delivery at exit (agentd/src/exec.rs:455, ordering atagentd/src/exec.rs:474-479, header atagentd/src/exec.rs:489-491). build_streamemits anygapfirst, drains the replayed backlog, then the live broadcast channel, and closes the body one step after the terminalexitevent (agentd/src/exec.rs:560, ending atagentd/src/exec.rs:604-615).
Flow 3: microvm cp –tar — an archive into the one confined write path
Section titled “Flow 3: microvm cp –tar — an archive into the one confined write path”commands::attached::cpresolves the direction from thevm:prefix before opening anything, so two local paths or two remote paths are refused by name rather than guessed at (microvms-cli/src/commands/attached.rs:805, resolver atmicrovms-cli/src/commands/attached.rs:902).- It attaches through the helper every command in that file starts with, which resolves the
region first because the region is what the proxy-token mint’s ARN is derived for
(
microvms-cli/src/commands/attached.rs:73). - The upload arm reads the local archive whole and sends it without inspecting it: the daemon’s
extractor is the only one in the system, and a client-side check would be a second set of
member rules that could disagree with it
(
microvms-cli/src/commands/attached.rs:812-835, stated atmicrovms-cli/src/commands/attached.rs:798-804). Session::upload_tardelegates tofiles::upload_tar, which buildsPUT /v1/fs/tar?path=...withcontent-type: application/x-tarand the archive bytes as the body (microvms-core/src/session/mod.rs:444,microvms-core/src/session/files.rs:98).Transport::requestprepends the proxy headers and the session’s bearer token to the caller’s own headers rather than replacing them, which is what keeps the content type on the request (microvms-core/src/session/mod.rs:106, header assembly atmicrovms-core/src/session/mod.rs:88).auth::require_tokenguards the control router before the body is polled, answering 503 when no token is installed and 401 on a mismatch, then draining a bounded prefix of the rejected body so the client sees the status rather than a TCP reset (agentd/src/auth.rs:62, verdicts atagentd/src/auth.rs:69-80, applied atagentd/src/routes.rs:66-69).fs::write_tarrefuses a relative extraction root, preflights free disk against that root before the body is spooled, then spools the body under the disk pacer (agentd/src/fs.rs:1433, preflight atagentd/src/fs.rs:1459-1461, spool atagentd/src/fs.rs:872).extract_intoruns underspawn_blockingand holds one confined directory handle for the whole extraction: ownership and xattrs are dropped, device and fifo members are refused, out-of-tree link targets are refused, and directory modes are replayed after all content lands. Success is 204 (agentd/src/fs.rs:621, refusals atagentd/src/fs.rs:702-707andagentd/src/fs.rs:742, deferred modes atagentd/src/fs.rs:810, dispatch and status atagentd/src/fs.rs:1479-1487).
See also
Section titled “See also”- processes — 13 shared source citations
- sequences — 11 shared source citations
- debugging guide — 9 shared source citations
- impact analysis — 9 shared source citations
- business logic — 8 shared source citations