Skip to main content
Use the Go module github.com/boxlite-ai/boxlite/sdks/go to run a command in an isolated microVM sandbox within minutes, without managing virtual machines, images, or networking yourself. Go has no SimpleBox-style one-line wrapper — you build the runtime and the box explicitly, in two calls.

Prerequisites

  • A machine with hardware virtualization — see Installation for the supported platforms.
  • Go 1.24 or newer, with CGO enabled (the default).
Install the module, then run the one-time setup step that fetches the prebuilt native library:
cmd/setup detects your platform and SDK version and downloads libboxlite.a plus boxlite.h from GitHub Releases straight into your Go module cache, so a later go build links against it with no separate install step. It prints Setup complete. when done; if the download stalls, see Troubleshooting.

Quick Example

Write the following into main.go, then run go build && ./<binary>.
Verified output from a real run against the published v0.9.7 module (go get + cmd/setup, no local build):

Parameters and Returns (Core API)

boxlite.NewRuntime / *Runtime (runtime handle)

*Box (box handle)

A failed start returns (nil, err). Reading res.ExitCode before checking err on a failed Exec call is a nil-pointer dereference, not a graceful zero value.

*Cmd (built via Command)

This differs from the standard library. os/exec’s Cmd.Run/Output return a *exec.ExitError on a non-zero exit. BoxLite’s Cmd does not — Run/Output return nil and you read ExitCode() yourself, exactly like Box.Exec.

ExecResult

Functional options (BoxOption, passed to Create / GetOrCreate)

Verified on this machine: with no options set, a fresh box reports nproc = 1 (default 1 vCPU) and its guest kernel is Linux 6.12.76.

Troubleshooting

Setup download times out

cmd/setup downloads a large (~100+ MB) archive under a fixed timeout. On a slow connection this can fail partway through — reproduced on this machine after successfully extracting libboxlite.a but before reaching boxlite.h. Re-run go run github.com/boxlite-ai/boxlite/sdks/go/cmd/setup; it detects the already-extracted files and resumes from there. It succeeded on the fourth attempt in this environment.

A failed Exec panics with a nil-pointer dereference

A start failure (for example, a missing binary) returns (nil, err) from Exec, not a res with a nonzero ExitCode. Always check err before reading res:

A non-zero exit code was not reported as an error

Exec, Cmd.Run, and Cmd.Output all return nil for err when the command itself ran and simply exited non-zero — check ExitCode yourself:

Distinguishing error types

Errors are *boxlite.Error with a .Code, checkable with the typed helpers:
IsNotFound / IsAlreadyExists / IsInvalidState / IsStopped cover the common cases.

Build error: -tags boxlite_dev behavior

If you are building this repository from source rather than consuming the published module, go build alone links against a prebuilt library (the one cmd/setup downloaded). Building against your own locally-compiled core instead requires make dev:go (from the repository root) followed by go build -tags boxlite_dev ./... — see Building from source.

Startup failure: no hardware virtualization (environment constraint)

  • Linux: confirm /dev/kvm exists and the current user is in the kvm group.
  • macOS (Apple Silicon): uses Hypervisor.framework and does not need /dev/kvm.
  • WSL2: enable nested virtualization and install KVM.
This surfaces as an error from Create/Exec, not a crash — check it like any other returned error.

Next Steps

  • Run any language or command inside the box: replace the "echo", "Hello from BoxLite!" arguments with your own, and "alpine:latest" with the image you need.
  • For streaming output or stdin, use Box.Command(...) (mirrors os/exec) or Box.StartExecution for the lowest-level Write / Wait / Kill / Signal access.
  • Other languages: see the Python quickstart, the Node.js quickstart, and the Rust quickstart.