Skip to main content

Sandbox

Struct Sandbox 

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

Clonable because two places run under the same policy without being able to share one value: the agent’s tool registry and the interface’s !command.

Implementations§

Source§

impl Sandbox

Source

pub fn new( cfg: &ToolsConfig, workspace: &Path, scripts_dir: Option<&Path>, ) -> Self

Source

pub fn off() -> Self

A sandbox that does nothing. Tests of the process-group kill (and anything else that wants the plain child) use this, so the two mechanisms stay separately testable.

Source

pub fn mode(&self) -> ShellIsolate

Source

pub fn is_on(&self) -> bool

Whether a command runs inside a namespace at all.

Source

pub fn refuses(&self) -> bool

Whether a mode that promised containment will refuse instead of running at all. True only for fs without bubblewrap; process degrades instead.

Source

pub fn refusal(&self) -> Option<ToolError>

The refusal a mode owes when it cannot be honoured, as the error the tool returns, or None when a command may run. One place, because three tools now ask it: shell, script and execute_code all start a process and all answer to the same policy (#550).

Source

pub fn degraded(&self) -> bool

Whether isolation was asked for and could not be given: the run happens anyway, and the result says so. Only process degrades; fs refuses in Sandbox::plan, because a read-only promise is not one to keep halfway.

Source

pub fn status(&self) -> String

What config check and the docs print: the mode, and whether the mechanism is there.

Source

pub fn plan( &self, program: &OsStr, args: &[OsString], cwd: &Path, ) -> Result<Plan, ToolError>

The program and arguments to run instead of program itself.

cwd is passed to bubblewrap rather than left to the caller so the directory is resolved inside the namespace, which is the only place it is guaranteed to mean the same thing.

Source

pub fn plan_with( &self, program: &OsStr, args: &[OsString], cwd: &Path, extra_rw: &[PathBuf], ) -> Result<Plan, ToolError>

Sandbox::plan with extra directories bound read-write at their own path under fs.

The tool bridge is why this exists: its socket is created after the sandbox is built, so a contained child can only reach it if the run binds the socket’s directory (#550). Under process the whole filesystem is already there, and under off nothing is wrapped.

Source

pub fn is_suggested_hide(&self, path: &Path) -> bool

Whether path is one of the hides the build suggests rather than one a person wrote.

Source

pub fn skipped_hides(&self) -> Vec<(&PathBuf, HideSkip)>

The hides a profile asked for that will not be applied, and why — for config check and the docs to name, rather than leave someone believing a path is hidden when it is not.

Trait Implementations§

Source§

impl Clone for Sandbox

Source§

fn clone(&self) -> Self

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§

§

impl Forget for Sandbox

§

impl Freeze for Sandbox

§

impl Move for Sandbox

§

impl RefUnwindSafe for Sandbox

§

impl Send for Sandbox
where RawVecInner: Send,

§

impl Sync for Sandbox
where RawVecInner: Sync,

§

impl Unpin for Sandbox
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for Sandbox

§

impl UnwindSafe for Sandbox
where RawVecInner: UnwindSafe,

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> 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> 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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 = !

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