Skip to main content

Sandbox

Struct Sandbox 

Source
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

Source

pub fn fs(&self) -> FileSystem

Read and write files in the guest.

Source

pub fn cache(&self) -> Cache

Save and restore guest directories under a key.

Source

pub fn linux(image: impl Into<String>) -> LinuxBuilder

Boot an OCI image as a Linux microVM.

Source

pub fn freebsd() -> FreebsdBuilder

Boot FreeBSD (EFI on macOS, PVH on Linux/amd64).

Source

pub fn netbsd() -> NetbsdBuilder

Boot NetBSD (direct-kernel boot everywhere).

Source

pub fn firmware( firmware: impl Into<String>, disk: impl Into<String>, ) -> FirmwareBuilder

Boot a raw disk through its UEFI loader.

Source

pub fn kernel(kernel: impl Into<String>) -> KernelBuilder

Boot a kernel directly, no bootloader.

Source

pub fn nanos(image: impl Into<String>) -> NanosBuilder

Boot a Nanos image (a path, or a bare name in ~/.ops/images).

Source

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).

Source

pub fn unikraft(path: impl Into<String>) -> UnikraftBuilder

Boot a Unikraft unikernel (a kraft project dir or a built image).

Source

pub fn solo5(path: impl Into<String>) -> Solo5Builder

Boot a Solo5 (MirageOS) unikernel (a .hvt binary or a project dir whose dist/ holds one).

Source

pub fn from_id(id: impl Into<String>) -> Sandbox

Wrap an already-known machine id without checking it exists.

Source

pub fn get(id: &str) -> Result<Sandbox>

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

Source

pub fn list(all: bool) -> Result<Vec<SandboxInfo>>

List machines. all includes exited ones (otherwise: running only).

Source

pub fn id(&self) -> &str

The machine’s Docker-style short id.

Source

pub fn ssh_port(&self) -> Option<u16>

Host port forwarded to the guest’s SSH, if the boot banner reported one.

Source

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()?;
Source

pub fn exec<I, S>(&self, argv: I) -> Result<ExecResult>
where I: IntoIterator<Item = S>, S: Into<String>,

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.

Source

pub fn logs(&self) -> Result<String>

Read the machine’s console log.

Source

pub fn boot_logs(&self) -> Result<String>

Read bsdkrun’s boot log for the machine.

Source

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.

Source

pub fn status(&self) -> Result<Option<SandboxInfo>>

Fetch this machine’s current status row, or None if it’s gone.

Source

pub fn is_running(&self) -> Result<bool>

Whether the machine is currently running.

Source

pub fn stop(&self) -> Result<()>

Stop the machine (BSD: clean power-off; Linux: SIGTERM).

Source

pub fn start(&self) -> Result<()>

Restart a stopped machine in place — same id, disk/rootfs, network.

Source

pub fn remove(&self, force: bool) -> Result<()>

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

Source

pub fn update(&self) -> UpdateBuilder

Change the recorded vCPU / RAM; applies on the next Sandbox::start.

sandbox.update().cpus(4).mem(2048).apply()?;
Source

pub fn connect_network(&self, network: &str) -> Result<()>

Join or switch this machine to a global network (next start).

Source

pub fn disconnect_network(&self) -> Result<()>

Detach this machine from its network. Applies on the next start.

Source

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()?;
Source

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()?;

Trait Implementations§

Source§

impl Clone for Sandbox

Source§

fn clone(&self) -> Sandbox

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Sandbox

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V