Back to Microsandbox

Runtime setup

docs/sdk/setup.mdx

0.6.95.0 KB
Original Source

Local sandboxes use the msb executable and libkrunfw library. Depending on the SDK and installation method, those runtime files may already be bundled or may need to be downloaded. Each SDK exposes helpers that let an application verify the runtime before creating its first sandbox.

The default install root is ~/.microsandbox/ (%USERPROFILE%\.microsandbox on Windows). Explicit setup is useful when you want installation failures to surface at process startup or when you are preparing an offline environment.

Install and verify

Check for the runtime and install it only when needed. These installation helpers are idempotent and reuse a matching installation.

<CodeGroup> ```rust Rust use microsandbox::setup;

if !setup::is_installed() { setup::install().await?; }


```typescript TypeScript
import { install, isInstalled } from "microsandbox";

if (!isInstalled()) {
  await install();
}
python
from microsandbox import install, is_installed

if not is_installed():
    await install()
go
import m "github.com/superradcompany/microsandbox/sdk/go"

if !m.IsInstalled() {
    if err := m.EnsureInstalled(ctx); err != nil {
        return err
    }
}
</CodeGroup>
SDKInstallCheckBehavior
Rustsetup::install() -> MicrosandboxResult<()>setup::is_installed() -> boolDownloads the SDK's pinned runtime and verifies it.
TypeScriptinstall(): Promise<void>isInstalled(): booleanDownloads the package's pinned runtime and verifies it.
Pythoninstall() -> None (async)is_installed() -> boolInstalls and verifies the runtime; release wheels normally bundle matching files.
GoEnsureInstalled(ctx, ...SetupOption) errorIsInstalled() boolInstalls msb and libkrunfw; the Go FFI library is embedded separately.

Customize installation

Rust and TypeScript expose builders for custom install roots, versions, verification, and forced downloads. Go exposes WithSkipDownload() for pre-provisioned or air-gapped environments. Python's setup helper uses the default installation behavior.

<CodeGroup> ```rust Rust use microsandbox::setup::Setup;

Setup::builder() .base_dir("/opt/microsandbox") .version("0.6.8") .skip_verify(false) .force(true) .build() .install() .await?;


```typescript TypeScript
import { setup } from "microsandbox";

await setup()
  .baseDir("/opt/microsandbox")
  .version("0.6.8")
  .skipVerify(false)
  .force(true)
  .install();
go
import m "github.com/superradcompany/microsandbox/sdk/go"

// Do not download. Return an error if the runtime was not pre-provisioned.
if err := m.EnsureInstalled(ctx, m.WithSkipDownload()); err != nil {
    return err
}
</CodeGroup>
OptionSDKsDescription
Install rootRust: base_dir(path)
TypeScript: baseDir(path)Override ~/.microsandbox/.
Runtime versionRust: version(version)
TypeScript: version(version)Install a specific runtime version instead of the SDK's pinned version.
Skip verificationRust: skip_verify(enabled)
TypeScript: skipVerify(enabled)Skip post-install verification.
Force downloadRust: force(enabled)
TypeScript: force(enabled)Download again even when matching files are present.
Skip downloadGo: WithSkipDownload()Require the runtime to be present without fetching it.

<span id="go-with-skip-download"></span> <span id="go-setupoption"></span>

In Go, WithSkipDownload() returns a SetupOption, whose exported type is func(*setupConfig). Options apply only to the first EnsureInstalled() call.

Override runtime paths

The Rust, TypeScript, and Python SDKs can override the process-wide libkrunfw path directly. Call the setter before creating a local sandbox.

<CodeGroup> ```rust Rust use microsandbox::set_libkrunfw_path;

set_libkrunfw_path("/opt/microsandbox/lib/libkrunfw.dylib");


```typescript TypeScript
import { setRuntimeLibkrunfwPath } from "microsandbox";

setRuntimeLibkrunfwPath("/opt/microsandbox/lib/libkrunfw.dylib");
python
from microsandbox import set_libkrunfw_path

set_libkrunfw_path("/opt/microsandbox/lib/libkrunfw.dylib")
</CodeGroup>

Environment variables work across the SDKs and take precedence over SDK-provided or configured paths:

VariablePurpose
MSB_PATHOverride the msb executable used by local SDK operations.
MSB_LIBKRUNFW_PATHOverride the libkrunfw shared library loaded by the process.

Set these process-wide overrides before creating any local sandbox. They do not belong to an individual sandbox configuration.

Inspect Go versions

Go also exposes the SDK's pinned release version and the version reported by the loaded FFI library:

go
sdkVersion := m.SDKVersion()

runtimeVersion, err := m.RuntimeVersion()
if err != nil {
    return err
}

SDKVersion() string does not load the FFI library. RuntimeVersion() (string, error) loads it automatically on first use and returns an error if loading fails.