Skip to main content

HostSandbox

Struct HostSandbox 

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

直接在宿主机上执行命令、读写真实文件系统的 sandbox。

这是默认实现,行为等价于“不沙箱“,不提供任何隔离。

Implementations§

Source§

impl HostSandbox

Source

pub fn new() -> Self

Source

pub fn with_root(root: impl Into<PathBuf>) -> Self

把命令限定在 root 目录下执行(以它为工作目录)。

注意:这是工作目录级别的限定——相对路径会落在 root 内,但不阻止绝对路径 (如 /etc/...)或 cd .. 逃逸,因此不是安全沙箱,只是“默认在这个目录里干活“。

Trait Implementations§

Source§

impl Default for HostSandbox

Source§

fn default() -> HostSandbox

Returns the “default value” for a type. Read more
Source§

impl Sandbox for HostSandbox

Source§

fn open<'life0, 'async_trait>( self: Arc<Self>, _session_id: &'life0 str, ) -> Pin<Box<dyn Future<Output = Result<Arc<dyn Sandbox>, SandboxError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

打开或恢复某个 session 对应的 sandbox。实现应保持幂等:同一 session 多次 open 应恢复到同一份状态,并且 bootstrap 逻辑不应重复破坏环境。
Source§

fn execute<'life0, 'life1, 'async_trait>( &'life0 self, command: &'life1 str, on_output: Option<OutputCallback>, ) -> Pin<Box<dyn Future<Output = Result<ExecOutput, SandboxError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

执行一条命令并返回结果。 Read more
Source§

fn save<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), SandboxError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

持久化自身当前状态。实例自己知道 session_id 和存到哪里,故无参。 默认不做事(真机文件系统本来就持久)。
Source§

fn fork<'life0, 'life1, 'async_trait>( &'life0 self, _to_session: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), SandboxError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

把自身当前状态复制给另一个会话 to_session。默认不支持。

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, 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<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