Skip to main content

AsyncSandbox

Struct AsyncSandbox 

Source
pub struct AsyncSandbox { /* private fields */ }
Expand description

Async wrapper around a Hanzo VM VM sandbox.

All VM operations are dispatched to a dedicated OS thread that owns the sandbox. This avoids Send/Sync constraints from the Apple Virtualization framework’s Objective-C objects.

Implementations§

Source§

impl AsyncSandbox

Source

pub async fn boot(config: SandboxConfig) -> Result<Self>

Boot a new sandbox VM with the given configuration.

Source

pub async fn exec(&self, argv: &[&str]) -> Result<ExecResult>

Execute a command and wait for the result.

Source

pub async fn exec_shell(&self, command: &str) -> Result<ExecResult>

Execute a command string via the given shell (defaults to /bin/sh).

Source

pub async fn exec_in(&self, shell: &str, command: &str) -> Result<ExecResult>

Execute a command string via a specific shell.

Use exec_in("bash", cmd) when you need login profile (PATH etc.), or exec_in("/bin/sh", cmd) for basic POSIX shell.

Source

pub async fn open_shell( &self, rows: u16, cols: u16, cwd: Option<&str>, argv: Option<&[&str]>, extra_env: HashMap<String, String>, ) -> Result<ShellHandle>

Spawn an interactive PTY session. If argv is None, opens a login shell (bash -l). If argv is Some, runs that command directly (no shell wrapper). If cwd is Some, the process starts in that directory.

Source

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

Read a file from the VM. Returns raw bytes.

Source

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

Write a file to the VM.

Source

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

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

Source

pub async fn add_port_forward( &self, host_port: u16, guest_port: u16, ) -> Result<()>

Add a port forward to a running sandbox.

Source

pub async fn dial_guest(&self, port: u16) -> Result<GuestStream>

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

This is the ingress counterpart to outbound proxying: it lets host-side code reach a server running in the sandbox without binding a local listener (unlike add_port_forward). The returned GuestStream is a blocking bidirectional pipe to 127.0.0.1:<port> inside the guest, suitable for bridging the guest service onto any transport (for example, a tunnel to the public internet). It works whether or not --allow-net is enabled.

For async I/O, take the inner stream with GuestStream::into_inner, set it non-blocking, and wrap it with tokio::net::TcpStream::from_std.

Source

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

Remove a file or directory inside the VM.

Source

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

List directory contents in the VM.

Source

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

Create a directory inside the VM. If recursive is true, creates parent directories as needed (like mkdir -p).

Source

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

Rename a file or directory inside the VM.

Source

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

Change file permissions inside the VM.

Source

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

Download a URL into the sandbox. If extract is true, the download is treated as a .tar.gz and extracted to path as a directory. strip_components mirrors tar --strip-components=N — set to 1 for tarballs wrapped in a single top-level directory (Node, Pi) and 0 for flat tarballs (single binary at root). Returns a channel that receives progress updates.

Source

pub async fn checkpoint(&self, name: &str) -> Result<()>

Save the current rootfs state as a named checkpoint (CoW clone). Future VMs can boot from this checkpoint via SandboxConfig::from.

Source

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

Watch a path inside the VM for filesystem changes (inotify-backed). Returns a handle whose receiver emits WatchEvents. Drop the handle to stop watching.

Source

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

Stop the VM and clean up resources.

Source

pub fn instance_dir(&self) -> &str

Get the instance directory path (contains the working rootfs copy).

Trait Implementations§

Source§

impl Drop for AsyncSandbox

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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<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