Module: Microsandbox

Defined in:
lib/microsandbox.rb,
lib/microsandbox/fs.rb,
lib/microsandbox/image.rb,
lib/microsandbox/errors.rb,
lib/microsandbox/volume.rb,
lib/microsandbox/metrics.rb,
lib/microsandbox/sandbox.rb,
lib/microsandbox/streams.rb,
lib/microsandbox/version.rb,
lib/microsandbox/snapshot.rb,
lib/microsandbox/log_entry.rb,
lib/microsandbox/exec_handle.rb,
lib/microsandbox/exec_output.rb

Overview

Microsandbox — lightweight microVM sandboxes for Ruby.

The runtime is embedded directly in the process via a Rust native extension; there is no daemon to install and no server to connect to. Creating a sandbox spawns a real microVM as a child process.

Examples:

Microsandbox::Sandbox.create("hello", image: "python") do |sb|
  puts sb.exec("python", ["-c", "print('Hello, World!')"]).stdout
end

Defined Under Namespace

Classes: Error, ExecEvent, ExecHandle, ExecOutput, ExecStdin, ExitStatus, FS, FsEntry, FsMetadata, Image, ImageDetail, ImageInfo, ImagePruneReport, LogEntry, LogStream, Metrics, MetricsStream, Sandbox, SandboxInfo, SandboxStopResult, Snapshot, SnapshotInfo, SnapshotVerifyReport, Volume, VolumeInfo

Constant Summary collapse

VERSION =

Gem version. Kept in lock-step with the upstream microsandbox runtime and the official Python/Node/Go SDKs (workspace version in the microsandbox repo).

"0.5.7"

Class Method Summary collapse

Class Method Details

.all_sandbox_metricsHash{String => Metrics}

Latest resource-usage snapshot for every running sandbox, keyed by name. Mirrors the official ‘all_sandbox_metrics`/`allSandboxMetrics` helpers.

Returns:



74
75
76
# File 'lib/microsandbox.rb', line 74

def all_sandbox_metrics
  Native.all_sandbox_metrics.transform_values { |m| Metrics.new(m) }
end

.installnil

Download and install the ‘msb` runtime + `libkrunfw` into `~/.microsandbox` (idempotent). Usually unnecessary: the native extension provisions the runtime at build time.

Returns:

  • (nil)


48
49
50
51
# File 'lib/microsandbox.rb', line 48

def install
  Native.install
  nil
end

.installed?Boolean

Returns whether the runtime is installed and resolvable.

Returns:

  • (Boolean)

    whether the runtime is installed and resolvable



54
55
56
# File 'lib/microsandbox.rb', line 54

def installed?
  Native.installed?
end

.runtime_pathString

Returns the resolved path to the ‘msb` runtime binary.

Returns:

  • (String)

    the resolved path to the ‘msb` runtime binary



59
60
61
# File 'lib/microsandbox.rb', line 59

def runtime_path
  Native.resolved_msb_path
end

.runtime_path=(path) ⇒ void

This method returns an undefined value.

Override the ‘msb` runtime path (highest-priority SDK tier of the resolver, below only the `MSB_PATH` environment variable).

Parameters:

  • path (String)


67
68
69
# File 'lib/microsandbox.rb', line 67

def runtime_path=(path)
  Native.set_runtime_msb_path(path.to_s)
end

.versionString

Returns the gem version.

Returns:

  • (String)

    the gem version



40
41
42
# File 'lib/microsandbox.rb', line 40

def version
  VERSION
end