Skip to main content

Sandbox

Struct Sandbox 

Source
pub struct Sandbox { /* private fields */ }

Implementations§

Source§

impl Sandbox

Source

pub fn builder() -> VmConfigBuilder

Source

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

Source

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

Source

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

Block until the guest control server accepts vsock connections.

Source

pub fn state_channel(&self) -> Receiver<VmState>

Source

pub fn exec( &self, argv: &[impl AsRef<str>], stdout: &mut impl Write, stderr: &mut impl Write, ) -> Result<i32>

Run a command non-interactively over vsock, streaming output to the provided writers. Returns the guest process exit code.

Source

pub fn exec_with_env( &self, argv: &[impl AsRef<str>], env: &HashMap<String, String>, stdout: &mut impl Write, stderr: &mut impl Write, ) -> Result<i32>

Source

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

Block until the guest’s vsock server answers, and give up saying so if it never does.

start returns when the VMM is running, which is earlier than the guest is reachable — kernel and guest init still have to happen. A caller that announces readiness at start hands its own caller a race it cannot see: the first request pays the whole wait, and on a loaded host pays past the connect budget and fails. Waiting here moves that wait to where it can be named.

Source

pub fn attest(&self, bind: &[u8; 64]) -> Result<Status>

Ask the guest’s platform for a report over bind.

The 64 bytes are what a verifier will check the report’s caller field against — Measurement::bind. A guest on ordinary hardware answers none, which is an answer: nothing here will sign for a measurement.

The read is bounded because a guest that predates this request drops the frame in silence, and a caller must not wait out a vm’s whole life on a question it was never able to hear.

Source

pub fn read_file(&self, path: &str) -> Result<Vec<u8>>

Source

pub fn write_file(&self, path: &str, content: &[u8]) -> Result<()>

Source

pub fn mkdir(&self, path: &str, recursive: bool) -> Result<()>

Source

pub fn download( &self, url: &str, path: &str, extract: bool, strip_components: u32, on_progress: impl Fn(DownloadProgress), ) -> Result<()>

Download a URL into the sandbox. Streams progress via the callback.

Source

pub fn read_dir(&self, path: &str) -> Result<ReadDirResponse>

Source

pub fn stat(&self, path: &str) -> Result<StatResponse>

Source

pub fn remove(&self, path: &str, recursive: bool) -> Result<()>

Source

pub fn discard_overlay(&self, path: &str) -> Result<()>

Discard overlay changes for a file: removes it from the upper dir, revealing the original host version from the lower layer.

Source

pub fn rename(&self, old_path: &str, new_path: &str) -> Result<()>

Source

pub fn copy(&self, src: &str, dst: &str, recursive: bool) -> Result<()>

Source

pub fn chmod(&self, path: &str, mode: u32) -> Result<()>

Source

pub fn open_exec( &self, argv: &[impl AsRef<str>], env: &HashMap<String, String>, cwd: Option<&str>, ) -> Result<TcpStream>

Open a vsock connection for streaming exec. Returns the raw stream after sending mounts + ExecRequest. Caller manages I/O (reads STDOUT/STDERR/EXIT frames, writes STDIN/KILL frames).

Source

pub fn open_shell( &self, argv: &[impl AsRef<str>], env: &HashMap<String, String>, rows: u16, cols: u16, ) -> Result<TcpStream>

Open a vsock connection for an interactive shell with PTY support. Like open_exec but with tty=true. Returns the raw stream after sending mounts + ExecRequest. Caller manages I/O using the binary frame protocol (STDIN/STDOUT/RESIZE/EXIT frames).

Source

pub fn open_shell_with_cwd( &self, argv: &[impl AsRef<str>], env: &HashMap<String, String>, rows: u16, cols: u16, cwd: Option<&str>, ) -> Result<TcpStream>

Source

pub fn open_watch(&self, path: &str, recursive: bool) -> Result<TcpStream>

Open a vsock connection for file watching. Returns a stream that emits WATCH_EVENT frames until the connection is closed.

Source

pub fn shell( &self, argv: &[impl AsRef<str>], env: &HashMap<String, String>, ) -> Result<i32>

Run an interactive shell session with PTY support. Puts the host terminal in raw mode, relays I/O bidirectionally over vsock, and handles SIGWINCH for window resize. Returns the guest process exit code.

Source

pub fn start_port_forwarding( &self, forwards: &[PortMapping], ) -> Result<PortForwardHandle>

Start port forwarding proxies. Returns a handle that stops all listeners when dropped.

Source

pub fn connect_forward(&self, guest_port: u16) -> Result<TcpStream>

Open a raw bidirectional stream to a TCP port listening inside the guest.

Unlike start_port_forwarding, this does not bind a host listener. It completes the vsock forward handshake and hands back the connected stream directly, so callers can bridge a guest service to an arbitrary transport (e.g. a tunnel) without a local port. The returned stream talks to 127.0.0.1:guest_port inside the guest and works whether or not networking (--allow-net) is enabled.

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more