Flow 1: Build, launch, execute, and clean up
Section titled “Flow 1: Build, launch, execute, and clean up”lifecycle::runopens a sandbox and raceslaunch_and_execagainst the interrupt future while retaining the sandbox for cleanup.crates/microvms-cli/src/commands/lifecycle.rs:437,crates/microvms-cli/src/commands/lifecycle.rs:642-688launch_and_execselects an existing image, builds from the supplied artifact, or callsensure_imageto build or reuse a content-addressed image.crates/microvms-cli/src/commands/lifecycle.rs:1020-1104Sandbox::runconstructs the launch payload, resolves the image identifier, calls the control plane, and records the accepted VM as pending.crates/microvms-app/src/sandbox.rs:1113,crates/microvms-app/src/sandbox.rs:1195-1274ControlPlane::run_microvm_reported, whichrun_microvmwraps, serializesRunMicrovm; the productionSignedTransport::sendsigns the request and sends it to AWS.crates/microvms-app/src/control/microvm.rs:433-489,crates/microvms-edges/src/control/transport.rs:149-200- The daemon’s
run_hookreceives the platform envelope, installs the bootstrap state, and runs the configured run handler before returning success.crates/agentd/src/routes.rs:222-314 - Unless
--no-waitis set,Sandbox::wait_until_runningwaits for the launch state and then callsSession::wait_until_readyto poll for bootstrap readiness.crates/microvms-cli/src/commands/lifecycle.rs:1163-1177,crates/microvms-app/src/sandbox.rs:1328-1364,crates/microvms-app/src/control/microvm.rs:647-708,crates/microvms-app/src/session/mod.rs:469-507 - When
--execis supplied,launch_and_execcallsSession::run_syncto start the workload, wait for its result, and acknowledge it.crates/microvms-cli/src/commands/lifecycle.rs:1199-1219,crates/microvms-app/src/session/mod.rs:564-570 - The CLI calls
tear_downafter the launch attempt;--keepretains resources, otherwise it requests termination and deletion of the image this run built.crates/microvms-cli/src/commands/lifecycle.rs:749-756,crates/microvms-cli/src/commands/lifecycle.rs:1309-1356
Flow 2: Stream command output
Section titled “Flow 2: Stream command output”attached::execattaches a session, starts the requested command, and selectsstream_execwhen--streamis set.crates/microvms-cli/src/commands/attached.rs:245-345Session::runsendsPOST /v1/exec/startand returns anExecHandleusing the daemon’s confirmed exec identifier.crates/microvms-app/src/session/mod.rs:520-556stream_execpasses the requested offset toExecHandle::for_each_eventand renders each received output, gap, or exit event.crates/microvms-cli/src/commands/attached.rs:482-537for_each_eventdelegates tofor_each_event_async, which drivesadvanceand retains its cursor for the final stream result.crates/microvms-app/src/session/exec.rs:483-590ExecHandle::attachadds request headers and opensGET /v1/exec/{id}/stream?offset=Nthrough the backend;ReqwestBackend::open_streamreturns the response header and chunk source.crates/microvms-app/src/session/exec.rs:727-751,crates/microvms-edges/src/session/http.rs:140-183- The daemon’s
streamhandler looks up the exec, snapshots its replay buffer, and constructs an SSE response frombuild_stream.crates/agentd/src/exec.rs:487-524 build_streamemits a gap when needed, drains replayed output, follows live output, and ends with the exec’s terminal event.crates/agentd/src/exec.rs:594-650- On a retryable interruption,
advancecan reconnect from the retained cursor within the configured retry limit; the callback driver returns the end reason and cursor to the CLI.crates/microvms-app/src/session/exec.rs:539-590,crates/microvms-app/src/session/exec.rs:596-650
Flow 3: Upload a file with microvm cp
Section titled “Flow 3: Upload a file with microvm cp”attached::cpresolves thevm:side, attaches a session, and reads the local file for an upload.crates/microvms-cli/src/commands/attached.rs:1502-1536- For an upload without
--tar,cpcallsSession::upload_filewith the remote path, bytes, and optional mode.crates/microvms-cli/src/commands/attached.rs:1539-1544 Session::upload_filepasses the upload toupload::upload, which first looks up the image’s default exec user. It readsGET /v1/healthonce per session, and when the response includes the default-user header, it runsid -u; id -gas that user. With no header, or a default user of root, it callsfiles::upload_file, which constructs aPUT /v1/fs/filerequest with an octet-stream body. For a non-root default user, root prepares a private staging directory and the same request writes the bytes into it. Root then hands the staged file to that user, and an exec as that user installs it at the destination.crates/microvms-app/src/session/mod.rs:593-600,crates/microvms-app/src/session/upload.rs:57-102,crates/microvms-app/src/session/upload.rs:104-166,crates/microvms-app/src/session/files.rs:65-77Transport::request_innercombines session and caller headers before sending through the backend;ReqwestBackend::sendcollects the HTTP response.crates/microvms-app/src/session/mod.rs:152-168,crates/microvms-edges/src/session/http.rs:117-137- The daemon router maps
PUT /v1/fs/filetofs::write_file.crates/agentd/src/routes.rs:151-177 write_fileparses the request, checks available disk space, creates missing parents, and opens the destination for replacement.crates/agentd/src/fs.rs:1222-1272write_filestreams the request body throughdisk::copy_guarded, applies a requested mode, and returns204 No Contenton success.crates/agentd/src/fs.rs:1280-1331- The application’s
Transport::sendchecks the response status beforeupload_filereturns success to the CLI.crates/microvms-app/src/session/mod.rs:172-177,crates/microvms-app/src/session/files.rs:65-77
See also
Section titled “See also”These pages cite many of the same source files as this one.