Skip to main content

IsolationPolicy

Struct IsolationPolicy 

Source
pub struct IsolationPolicy {
    pub ro_binds: Vec<RoBind>,
    pub rw_binds: Vec<RwBind>,
    pub work_host: Option<PathBuf>,
    pub network: bool,
    pub env_allowlist: Vec<String>,
}
Expand description

What the sandbox does and doesn’t let a stage reach.

Derived from a stage’s EffectSet via IsolationPolicy::from_effects. Callers rarely construct this manually; it’s shaped so the stage executor can translate it into backend-specific flags (bwrap args in Phase 1, unshare+landlock+seccomp in Phase 2). Serde-enabled so downstream consumers (e.g. the noether-sandbox binary) can exchange policies over IPC.

Fields§

§ro_binds: Vec<RoBind>

Read-only bind mounts. Always includes /nix/store so Nix-pinned runtimes resolve inside the sandbox.

§rw_binds: Vec<RwBind>

Read-write bind mounts. Empty by default; never populated by Self::from_effects (effects alone don’t carry enough information to justify a trust widening — see RwBind).

§Interaction with ro_binds and work_host (mount order)

bwrap processes bind flags in argv order; a later flag whose sandbox path sits under an earlier flag’s sandbox path shadows the earlier one for that subtree. build_bwrap_command emits binds in this fixed order:

  1. rw_binds (this field) — --bind <host> <sandbox> per entry.
  2. ro_binds--ro-bind <host> <sandbox> per entry.
  3. work_host--bind <host> /work (if Some), else --dir /work (sandbox-private tmpfs).

Why RW-then-RO: the agentspec-ish pattern is “this agent operates on my ~/projects/foo directory RW, but its .ssh subdirectory stays RO.” With RW emitted first, the narrower RO shadows the broader RW — which is the default-ergonomic outcome. Reversing the order would make the RW bind silently override an attempt to protect a subpath.

work_host renders after both vectors, so a work_host that happens to sit under an earlier bind wins at /work. This matches the pre-existing behaviour on ro_binds alone and is the mapping the executor expects.

§work_host: Option<PathBuf>

Scratch directory strategy for /work inside the sandbox.

  • None (recommended, and the default from Self::from_effects) → bwrap creates /work as a sandbox-private tmpfs via --dir /work. No host-side path exists; cleanup happens automatically when the sandbox exits; a malicious host user can’t race to write predicatable filenames into the work dir before the stage runs.
  • Some(host)--bind <host> /work. Host dir must exist and be writable by the sandbox’s effective UID (65534 by default). Only for callers that need to inspect the work dir after execution — e.g., an integration test.
§network: bool

Inherit the host’s network namespace (true) or unshare into a fresh empty one (false). Only true when the stage has Effect::Network.

§env_allowlist: Vec<String>

Environment variables to pass through to the sandboxed process. Everything else in the parent environment is cleared.

Implementations§

Source§

impl IsolationPolicy

Source

pub fn from_effects(effects: &EffectSet) -> Self

Build the policy for a stage with the given effects.

Defaults to a sandbox-private /work (tmpfs, no host-side state). Callers that need a host-visible work dir can swap in Self::with_work_host.

Source

pub fn with_work_host(self, host: PathBuf) -> Self

Override the sandbox’s /work to bind a caller-provided host directory. The directory must already exist and be writable by the sandbox effective UID (65534). Consumers mostly leave the default (tmpfs).

Trait Implementations§

Source§

impl Clone for IsolationPolicy

Source§

fn clone(&self) -> IsolationPolicy

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for IsolationPolicy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for IsolationPolicy

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for IsolationPolicy

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> 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> Same for T

Source§

type Output = T

Should always be Self
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 = 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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,