pub struct Sandbox { /* private fields */ }Expand description
A handle to a running (or stopped) bsdkrun microVM.
Create one with the per-kind builders (Sandbox::linux,
Sandbox::freebsd, …), reconnect with Sandbox::get, or enumerate
with Sandbox::list.
Implementations§
Source§impl Sandbox
impl Sandbox
Sourcepub fn linux(image: impl Into<String>) -> LinuxBuilder
pub fn linux(image: impl Into<String>) -> LinuxBuilder
Boot an OCI image as a Linux microVM.
Sourcepub fn freebsd() -> FreebsdBuilder
pub fn freebsd() -> FreebsdBuilder
Boot FreeBSD (EFI on macOS, PVH on Linux/amd64).
Sourcepub fn netbsd() -> NetbsdBuilder
pub fn netbsd() -> NetbsdBuilder
Boot NetBSD (direct-kernel boot everywhere).
Sourcepub fn firmware(
firmware: impl Into<String>,
disk: impl Into<String>,
) -> FirmwareBuilder
pub fn firmware( firmware: impl Into<String>, disk: impl Into<String>, ) -> FirmwareBuilder
Boot a raw disk through its UEFI loader.
Sourcepub fn kernel(kernel: impl Into<String>) -> KernelBuilder
pub fn kernel(kernel: impl Into<String>) -> KernelBuilder
Boot a kernel directly, no bootloader.
Sourcepub fn nanos(image: impl Into<String>) -> NanosBuilder
pub fn nanos(image: impl Into<String>) -> NanosBuilder
Boot a Nanos image (a path, or a bare name in ~/.ops/images).
Sourcepub fn osv(image: impl Into<String>) -> OsvBuilder
pub fn osv(image: impl Into<String>) -> OsvBuilder
Boot an OSv image (an aarch64 loader.img, or on x86_64 the loader
ELF plus a OsvBuilder::disk).
Sourcepub fn unikraft(path: impl Into<String>) -> UnikraftBuilder
pub fn unikraft(path: impl Into<String>) -> UnikraftBuilder
Boot a Unikraft unikernel (a kraft project dir or a built image).
Sourcepub fn solo5(path: impl Into<String>) -> Solo5Builder
pub fn solo5(path: impl Into<String>) -> Solo5Builder
Boot a Solo5 (MirageOS) unikernel (a .hvt binary or a project dir
whose dist/ holds one).
Sourcepub fn from_id(id: impl Into<String>) -> Sandbox
pub fn from_id(id: impl Into<String>) -> Sandbox
Wrap an already-known machine id without checking it exists.
Sourcepub fn get(id: &str) -> Result<Sandbox>
pub fn get(id: &str) -> Result<Sandbox>
Reconnect to an existing machine by id (a unique prefix is enough).
Sourcepub fn list(all: bool) -> Result<Vec<SandboxInfo>>
pub fn list(all: bool) -> Result<Vec<SandboxInfo>>
List machines. all includes exited ones (otherwise: running only).
Sourcepub fn ssh_port(&self) -> Option<u16>
pub fn ssh_port(&self) -> Option<u16>
Host port forwarded to the guest’s SSH, if the boot banner reported one.
Sourcepub fn command(&self, program: impl Into<String>) -> CommandBuilder
pub fn command(&self, program: impl Into<String>) -> CommandBuilder
Start building a guest command: program first, everything else chained.
let out = sandbox
.command("node")
.args(["-e", "console.log(1)"])
.env("X", "hi")
.cwd("/app")
.run()?;Sourcepub fn exec<I, S>(&self, argv: I) -> Result<ExecResult>
pub fn exec<I, S>(&self, argv: I) -> Result<ExecResult>
Run an argv in the guest through its exec agent — the shorthand for
Sandbox::command with no extra options.
A non-zero exit is reported in the ExecResult, not raised; chain
ExecResult::ok_or_err to turn it into an error.
Sourcepub fn shell(&self) -> Result<i32>
pub fn shell(&self) -> Result<i32>
Attach an interactive shell to the machine (inherits the terminal).
Blocks until the shell exits and returns its exit code.
Sourcepub fn status(&self) -> Result<Option<SandboxInfo>>
pub fn status(&self) -> Result<Option<SandboxInfo>>
Fetch this machine’s current status row, or None if it’s gone.
Sourcepub fn is_running(&self) -> Result<bool>
pub fn is_running(&self) -> Result<bool>
Whether the machine is currently running.
Sourcepub fn start(&self) -> Result<()>
pub fn start(&self) -> Result<()>
Restart a stopped machine in place — same id, disk/rootfs, network.
Sourcepub fn remove(&self, force: bool) -> Result<()>
pub fn remove(&self, force: bool) -> Result<()>
Remove the machine and its state. force stops it first if running.
Sourcepub fn update(&self) -> UpdateBuilder
pub fn update(&self) -> UpdateBuilder
Change the recorded vCPU / RAM; applies on the next Sandbox::start.
sandbox.update().cpus(4).mem(2048).apply()?;Sourcepub fn connect_network(&self, network: &str) -> Result<()>
pub fn connect_network(&self, network: &str) -> Result<()>
Join or switch this machine to a global network (next start).
Sourcepub fn disconnect_network(&self) -> Result<()>
pub fn disconnect_network(&self) -> Result<()>
Detach this machine from its network. Applies on the next start.
Sourcepub fn ssh_setup(&self) -> SshSetupBuilder
pub fn ssh_setup(&self) -> SshSetupBuilder
Install SSH keys in the guest (ssh setup, via the agent).
With no key, the CLI installs your local ~/.ssh/*.pub keys.
sandbox.ssh_setup().user("tsiry").key("~/.ssh/work.pub").run()?;Sourcepub fn tailscale_up(&self) -> TailscaleUpBuilder
pub fn tailscale_up(&self) -> TailscaleUpBuilder
Put the guest on your tailnet (tailscale setup, via the agent).
sandbox.tailscale_up().authkey("tskey-auth-...").hostname("web").run()?;