Skip to main content

SandboxBackend

Trait SandboxBackend 

Source
pub trait SandboxBackend: Send + Sync {
    // Required methods
    fn read<'a>(&'a self, path: &'a str) -> BoxFuture<'a, Result<String>>;
    fn read_bytes<'a>(
        &'a self,
        path: &'a str,
        max_bytes: usize,
    ) -> BoxFuture<'a, Result<Vec<u8>>>;
    fn write<'a>(
        &'a self,
        path: &'a str,
        content: &'a str,
    ) -> BoxFuture<'a, Result<()>>;
    fn execute<'a>(
        &'a self,
        command: &'a str,
        sandbox_mode: SandboxMode,
        network_access: NetworkAccess,
        mode: CommandMode,
        output: CommandOutputSink,
    ) -> BoxFuture<'a, Result<CommandOutput>>;

    // Provided methods
    fn isolated_execution(&self) -> Result<Arc<dyn SandboxBackend>> { ... }
    fn temporary_directory(&self) -> Option<PathBuf> { ... }
    fn start_worker(
        &self,
        _command: &WorkerCommand,
        _sandbox_mode: SandboxMode,
        _network_access: NetworkAccess,
    ) -> Result<WorkerProcess> { ... }
    fn worker_connection<'a>(
        &'a self,
        _session_id: &'a str,
        _sandbox_mode: SandboxMode,
    ) -> BoxFuture<'a, Result<DuplexStream>> { ... }
    fn execute_authorized<'a>(
        &'a self,
        _command: &'a str,
        _sandbox_mode: SandboxMode,
        _network_access: NetworkAccess,
        _mode: CommandMode,
        _output: CommandOutputSink,
        _authorization: &'a CommandAuthorization,
    ) -> BoxFuture<'a, Result<Option<CommandOutput>>> { ... }
}
Expand description

Implements one sandbox execution environment.

Returned futures are Send and may be dropped during execution. Backends own cancellation cleanup for the processes and resources they launch; dropping a future must not leave unmanaged commands running. Sandbox owns approval and background-command tracking, not arbitrary backend cleanup.

Required Methods§

Source

fn read<'a>(&'a self, path: &'a str) -> BoxFuture<'a, Result<String>>

Reads a UTF-8 file.

Source

fn read_bytes<'a>( &'a self, path: &'a str, max_bytes: usize, ) -> BoxFuture<'a, Result<Vec<u8>>>

Reads one binary file through a single bounded open handle.

Source

fn write<'a>( &'a self, path: &'a str, content: &'a str, ) -> BoxFuture<'a, Result<()>>

Writes a UTF-8 file.

Source

fn execute<'a>( &'a self, command: &'a str, sandbox_mode: SandboxMode, network_access: NetworkAccess, mode: CommandMode, output: CommandOutputSink, ) -> BoxFuture<'a, Result<CommandOutput>>

Runs a shell command and forwards drained output under the requested isolation.

Provided Methods§

Source

fn isolated_execution(&self) -> Result<Arc<dyn SandboxBackend>>

Creates an independent temporary area and execution lifetime for a child agent.

Source

fn temporary_directory(&self) -> Option<PathBuf>

Reports the private temporary path visible to command and file tools.

Source

fn start_worker( &self, _command: &WorkerCommand, _sandbox_mode: SandboxMode, _network_access: NetworkAccess, ) -> Result<WorkerProcess>

Launches a persistent framed runtime inside this backend’s execution boundary.

Source

fn worker_connection<'a>( &'a self, _session_id: &'a str, _sandbox_mode: SandboxMode, ) -> BoxFuture<'a, Result<DuplexStream>>

Opens an authorized host-service channel for one worker evaluation. Dropping the channel ends its authority; requests are never replayed.

Source

fn execute_authorized<'a>( &'a self, _command: &'a str, _sandbox_mode: SandboxMode, _network_access: NetworkAccess, _mode: CommandMode, _output: CommandOutputSink, _authorization: &'a CommandAuthorization, ) -> BoxFuture<'a, Result<Option<CommandOutput>>>

Runs a shell command only when authorization launches it atomically.

Backends without an atomic launch boundary fail closed.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§