bsdkrun

Gleam SDK for bsdkrun — a Firecracker-style microVM launcher for BSD and Linux guests on macOS and Linux, built on libkrun.

The SDK is a thin, stateless wrapper around the bsdkrun binary: it builds argv, shells out through an Erlang port, and decodes the JSON output.

import bsdkrun
import bsdkrun/args
import bsdkrun/types

pub fn main() {
  let assert Ok(box) = bsdkrun.create(args.linux("alpine"))
  let assert Ok(res) = bsdkrun.exec(box, ["uname", "-a"])
  echo types.text(res)
  let assert Ok(Nil) = bsdkrun.stop(box)
}

This module holds the shortest path to a running machine. Everything else lives in the submodules:

The binary is resolved from bsdkrun/binary.set_binary_path, $BSDKRUN_BIN, bsdkrun on $PATH, or an in-repo dev build — in that order.

Values

pub fn create(
  opts: args.CreateOptions,
) -> Result(sandbox.Sandbox, error.Error)

Boot a new microVM (detached) and return a handle to it. See bsdkrun/args for the option builders.

pub fn exec(
  box: sandbox.Sandbox,
  command: List(String),
) -> Result(types.CommandResult, error.Error)

Run a command in the guest with the default options. Use bsdkrun/sandbox.exec when you need env vars, a TTY, stdin, or a cwd.

pub fn get(id: String) -> Result(sandbox.Sandbox, error.Error)

Reconnect to an existing machine by id — a unique prefix is enough.

pub fn is_running(box: sandbox.Sandbox) -> Bool

Whether the machine is currently running.

pub fn list() -> Result(List(types.SandboxInfo), error.Error)

List running machines.

pub fn list_all(
  all: Bool,
) -> Result(List(types.SandboxInfo), error.Error)

List machines, including exited ones when all is True.

pub fn logs(box: sandbox.Sandbox) -> Result(String, error.Error)

Read the machine’s console log.

pub fn remove(
  box: sandbox.Sandbox,
  force: Bool,
) -> Result(Nil, error.Error)

Remove the machine and its state. force stops it first if running.

pub fn start(box: sandbox.Sandbox) -> Result(Nil, error.Error)

Restart a stopped machine in place.

pub fn status(
  box: sandbox.Sandbox,
) -> Result(option.Option(types.SandboxInfo), error.Error)

This machine’s current status row, or None if it is gone.

pub fn stop(box: sandbox.Sandbox) -> Result(Nil, error.Error)

Stop the machine.

Search Document