SandboxConfig

Struct SandboxConfig 

Source
pub struct SandboxConfig {
    pub fs_read: PathPolicy,
    pub fs_write: PathPolicy,
    pub net_outgoing: NetPolicy,
    pub net_incoming: NetPolicy,
    pub env_vars: Option<HashSet<String>>,
    pub working_dir: Option<PathBuf>,
    pub isolate_temp: bool,
}
Expand description

Configuration for the sandbox environment.

Fields§

§fs_read: PathPolicy

Policy for filesystem read access.

§fs_write: PathPolicy

Policy for filesystem write access.

§net_outgoing: NetPolicy

Policy for outgoing network requests.

§net_incoming: NetPolicy

Policy for incoming network connections.

§env_vars: Option<HashSet<String>>

Allowed environment variable names (None = all denied).

§working_dir: Option<PathBuf>

Working directory for the script.

§isolate_temp: bool

Whether to isolate temp directory.

Implementations§

Source§

impl SandboxConfig

Source

pub fn locked() -> Self

Create a completely locked-down sandbox configuration.

Source

pub fn permissive() -> Self

Create a permissive sandbox configuration (use with caution).

Source

pub fn with_read_paths<I, P>(self, paths: I) -> Self
where I: IntoIterator<Item = P>, P: Into<PathBuf>,

Allow reading from specific paths.

Source

pub fn with_write_paths<I, P>(self, paths: I) -> Self
where I: IntoIterator<Item = P>, P: Into<PathBuf>,

Allow writing to specific paths.

Source

pub fn with_allowed_hosts<I, S>(self, hosts: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Allow outgoing requests to specific hosts.

Source

pub fn with_env_vars<I, S>(self, vars: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Allow access to specific environment variables.

Source

pub fn with_working_dir<P: Into<PathBuf>>(self, path: P) -> Self

Set the working directory.

Source

pub fn with_temp_isolation(self) -> Self

Enable temp directory isolation.

Source

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

Check if reading from a path is allowed.

Source

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

Check if writing to a path is allowed.

Source

pub fn can_connect(&self, host: &str) -> bool

Check if connecting to a host is allowed.

Source

pub fn can_access_env(&self, name: &str) -> bool

Check if an environment variable is accessible.

Trait Implementations§

Source§

impl Clone for SandboxConfig

Source§

fn clone(&self) -> SandboxConfig

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 SandboxConfig

Source§

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

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

impl Default for SandboxConfig

Source§

fn default() -> SandboxConfig

Returns the “default value” for a type. 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, 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> 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.