Skip to main content
Local sandboxes need msb and libkrunfw. Call the setup helper once at application startup: it reuses an existing runtime or installs one when missing. Sandbox creation does not download it automatically. Cloud sandboxes do not need a local runtime.

Set up the runtime

The default installation directory is ~/.microsandbox (%USERPROFILE%\.microsandbox on Windows). Keep msb and libkrunfw from the same runtime bundle.

Choose a setup operation

Use ensure for normal startup. The calls below are alternatives; choose the one your application needs.
Ensure does not repair incomplete installations or ignore invalid explicit paths.

How runtime selection works

The SDK checks these locations in order: It first checks explicit paths: environment variables, process-level setters, then configured paths. Next it checks the runtime home: configured home, then MSB_HOME, then ~/.microsandbox. Finally it checks the SDK package for bundled binaries, when available.
A local backend captures its effective home, relative directory overrides, configured runtime paths, and registry CA certificate path when it is constructed. Later changes to the working directory or MSB_HOME do not move that backend’s files. Construct a new backend to select another home.Relative host paths in global config.json and managed configuration resolve against the contributing file’s directory. Programmatic paths and environment defaults use the caller’s working directory.Process-level SDK runtime setters capture relative paths when registered; environment runtime overrides are captured during backend construction, below managed policy. Existing saved sandbox records retain their legacy relative-path interpretation without rewriting.A complete home installation wins over bundled Python and Node runtimes, even if its version differs from the SDK. Updating an SDK does not replace that installation. Go also reuses a complete home installation. Managed runtime paths override user choices.
To use a custom installation, set both MSB_PATH and MSB_LIBKRUNFW_PATH before constructing a backend. See path overrides for SDK setters and precedence details.

Advanced setup

Inspect legacy storage

Storage diagnostics require an explicit list of sandbox names or an explicit whole-home selection. They report readiness, blockers, candidate views, and estimated staging space without installing a runtime or migrating sandbox data. Running results are provisional; SQLite may maintain its normal WAL read-lock sidecars.
  • Rust: setup::diagnose_storage(GlobalConfigPatch, StorageSelection); recover stopped storage with Sandbox::recover_storage(name, StorageRecoveryOptions).
  • Python: diagnose_storage(names, *, all_sandboxes=False, config=None); Sandbox.recover_storage(name, ...).
  • TypeScript: diagnoseStorage(selection, config?); Sandbox.recoverStorage(name, options?).
  • Go: DiagnoseStorage(ctx, config, selection); RecoverStorage(ctx, name, options).
  • Ruby: Microsandbox.diagnose_storage(names:, all_sandboxes:, home:); Microsandbox::Sandbox.recover_storage(name, ...).
Recovery never starts or stops a VM. macOS legacy recovery requires the explicit legacy_writers_stopped confirmation (legacyWritersStopped in TypeScript, LegacyWritersStopped in Go) under the maintenance conditions in the migration guide. Empty selections import or resume the validated current view; explicit candidate selection requires acknowledgement that it may omit later writes. See sandbox storage migration for the CLI workflow and recovery limits.

Bring your own runtime

Use an existing msb executable and its matching libkrunfw library instead of downloading a runtime at application startup. Install the pair with the CLI installer, or provision it yourself. Set both paths before starting your application. Replace these example paths with your installation:
Use the resolve helper to check that the pair is available without installing anything. These environment variables also select the runtime for subsequent sandbox operations; see path overrides for precedence.
All SDKs can use the runtime paths above. You still need to install the SDK itself, including its native bindings. The packaging details differ:

Use a custom kernel

If your workload needs additional Linux kernel features, build a custom libkrunfw, the library that bundles the guest kernel. This applies to local sandboxes; it does not change the managed cloud kernel.
Start from the vendor/libkrunfw revision pinned by your microsandbox release in our libkrunfw fork. It includes the kernel patches microsandbox relies on; an upstream build may not be compatible.
  1. Enable the required kernel options or apply your patches, then follow the build instructions for your platform and architecture.
  2. Select the compatible msb executable and your rebuilt library before starting your application.
For example, on Linux, replace these paths with your executable and custom library:
You can also use the SDK path setters before constructing a backend. Boot a fresh guest to use the new kernel. Running guests and full snapshots retain their existing kernel.

Offline installation

Use a directory or archive source to install a pre-downloaded release bundle. To require an installation that already exists, call the resolve helper instead of ensure. See installation examples and options and offline deployment.

Embedded runtime

If your SDK build includes an embedded runtime archive, you can install from it without downloading. Select the embedded_archive source in the installation options. Ensure reuses an existing runtime before extracting the archive. Resolve only finds an existing installation; it does not extract one.

Troubleshooting

For existing installations, see the v0.7 migration guide before upgrading a shared database. Helper details are available below.

API reference

Python, TypeScript, and Go accept a RuntimeConfig and InstallOptions. Their per-call home and binary-path overrides are layered on persisted global configuration. Rust accepts GlobalConfig and InstallOptions directly. Environment binary-path overrides retain the highest priority.Use the directory source to provision a runtime from a flat release-bundle directory containing msb and libkrunfw side by side, without downloading:
An embedded source requires a native SDK built with an embedded runtime archive. If unavailable, explicit installation errors. Ensure still reuses an existing pair before acquisition, even when an embedded source is requested. To require a pre-provisioned runtime, call resolve directly. Each call uses its own configuration; Go no longer caches a process-wide successful setup result.
Use process-wide SDK setters where available, or the environment variables below. Go uses environment variables for process-wide overrides and RuntimeConfig for individual setup calls. Call setters before creating a local sandbox. Automatic package discovery is a fallback and does not occupy the explicit setter slot. A public libkrunfw setter overrides the library for the selected executable, whether that executable comes from configured paths, home, or a package.
Set runtime paths before constructing a backend. Each backend captures these settings; create a new backend to pick up changes. Environment variables work across the SDKs and take precedence over SDK-provided or user-configured paths. Managed runtime paths take precedence over all three:Set these process-wide overrides before creating any local sandbox. Prefer setting MSB_PATH and MSB_LIBKRUNFW_PATH together to select a matching pair. MSB_PATH alone may resolve a library adjacent to that executable; MSB_LIBKRUNFW_PATH alone is incomplete and fails closed. An incomplete explicit pair is not repaired by falling back to another installation. MSB_AGENTD_PATH takes precedence over global paths.agentd; the selected file is read eagerly and must name a compatible Linux ELF executable. These variables do not belong to an individual sandbox configuration.
TypeScript and Rust can read the Cargo package version embedded in an msb executable without running it. This is an optional inspection of the specified file; firmware and a complete runtime installation are not required.
Rust returns Option<setup::Version> and TypeScript returns string | null. Older executables without the version section produce None or null. Invalid executable metadata, malformed version sections and file access failures are errors. The reader supports ELF, PE and thin or universal Mach-O files, limits metadata reads to 4 MiB and version contents to 256 bytes, and never falls back to executing msb --version. Universal Mach-O slices must agree on the version, including section absence. The version identifies the build; it does not authenticate the executable or guarantee feature compatibility.Sandbox startup separately resolves a tested launch contract for the selected runtime. When embedded version metadata is absent, startup may run a bounded msb --version probe and cache the result for that native executable’s identity within the SDK process. Replacing the executable invalidates that cache. This startup behavior does not change the read-only version inspection methods above.
Go setup helpers may load the SDK’s embedded FFI library on first use; resolve does not install host runtime binaries.Go also exposes the SDK’s pinned release version and the version reported by the loaded FFI library:
SDKVersion() string does not load the FFI library. RuntimeVersion() (string, error) loads it automatically on first use and returns an error if loading fails.
These APIs were replaced in v0.7.0. Use this mapping when upgrading from v0.6; new applications should use the current helpers above.
  • TypeScript: replace the setup / Setup builder with runtime helpers accepting RuntimeConfig and InstallOptions.
  • Go: replace SetupOption with RuntimeConfig and InstallOptions. Replace WithSkipDownload with ResolveRuntime when installation must be avoided.
Install and ensure now return the selected runtime paths. Rust’s four helper names and Ruby’s setup API are unchanged. See setup operations.