Skip to main content

SandboxPolicy

Enum SandboxPolicy 

Source
pub enum SandboxPolicy {
    ReadOnly {
        network_access: bool,
        network_allowlist: Vec<NetworkAllowlistEntry>,
    },
    WorkspaceWrite {
        writable_roots: Vec<WritableRoot>,
        network_access: bool,
        network_allowlist: Vec<NetworkAllowlistEntry>,
        sensitive_paths: Option<Vec<SensitivePath>>,
        resource_limits: ResourceLimits,
        seccomp_profile: SeccompProfile,
        exclude_tmpdir_env_var: bool,
        exclude_slash_tmp: bool,
    },
    DangerFullAccess,
    ExternalSandbox {
        description: String,
    },
}
Expand description

Sandbox policy determining what operations are permitted during execution.

This follows the Codex sandboxing model with three main variants:

  • ReadOnly: Only read operations allowed (safe for viewing files)
  • WorkspaceWrite: Can write within specified directories
  • DangerFullAccess: No restrictions (dangerous, requires explicit approval)

The field guide’s three-question model:

  1. What is shared between this code and the host? (boundary)
  2. What can the code touch? (policy - this enum)
  3. What survives between runs? (lifecycle)

Variants§

§

ReadOnly

No write access to the filesystem; network access may be restricted or allowlisted.

Fields

§network_access: bool

Whether network access is enabled when no allowlist is set.

§network_allowlist: Vec<NetworkAllowlistEntry>

Domain-based network egress allowlist.

§

WorkspaceWrite

Write access limited to the specified roots; network controlled by allowlist.

Fields

§writable_roots: Vec<WritableRoot>

Directories where write access is permitted.

§network_access: bool

Whether network access is allowed (legacy boolean, use network_allowlist for fine-grained control).

§network_allowlist: Vec<NetworkAllowlistEntry>

Domain-based network egress allowlist. When non-empty, only connections to these destinations are permitted. Following field guide: “Default-deny outbound network, then allowlist.”

§sensitive_paths: Option<Vec<SensitivePath>>

Sensitive paths to block (credentials, SSH keys, cloud configs). Following field guide: prevents “policy leakage” of credentials. Defaults to DEFAULT_SENSITIVE_PATHS if None.

§resource_limits: ResourceLimits

Resource limits (memory, PIDs, disk, CPU). Following field guide: prevents fork bombs, memory exhaustion.

§seccomp_profile: SeccompProfile

Seccomp-BPF profile for Linux syscall filtering. Following field guide: “Landlock + seccomp is the recommended Linux pattern.”

§exclude_tmpdir_env_var: bool

Exclude the TMPDIR environment variable from writable roots.

§exclude_slash_tmp: bool

Exclude /tmp from writable roots.

§

DangerFullAccess

Full access - no sandbox restrictions applied. Use with extreme caution.

§

ExternalSandbox

External sandbox - the caller is responsible for sandbox setup.

Fields

§description: String

Description of the external sandbox mechanism.

Implementations§

Source§

impl SandboxPolicy

Source

pub fn read_only() -> Self

Create a read-only policy.

Source

pub fn new_read_only_policy() -> Self

Create a new read-only policy (alias for backwards compatibility).

Source

pub fn read_only_with_network( network_allowlist: Vec<NetworkAllowlistEntry>, ) -> Self

Create a read-only policy with a network allowlist.

Source

pub fn read_only_with_full_network() -> Self

Create a read-only policy with full network access.

Source

pub fn workspace_write(writable_roots: Vec<PathBuf>) -> Self

Create a workspace-write policy with specified roots. Uses default sensitive path blocking and strict seccomp profile.

Source

pub fn workspace_write_with_sensitive_paths( writable_roots: Vec<PathBuf>, sensitive_paths: Vec<SensitivePath>, ) -> Self

Create a workspace-write policy with custom sensitive path settings.

Source

pub fn workspace_write_full( writable_roots: Vec<PathBuf>, network_allowlist: Vec<NetworkAllowlistEntry>, sensitive_paths: Option<Vec<SensitivePath>>, resource_limits: ResourceLimits, seccomp_profile: SeccompProfile, ) -> Self

Create a fully-configured workspace-write policy.

Source

pub fn full_access() -> Self

Create a full-access policy (dangerous).

Source

pub fn has_full_network_access(&self) -> bool

Check if the policy allows full network access (unrestricted).

Source

pub fn has_network_allowlist(&self) -> bool

Check if the policy has a network allowlist (domain-restricted access).

Source

pub fn network_allowlist(&self) -> &[NetworkAllowlistEntry]

Get the network allowlist entries, if any.

Source

pub fn is_network_allowed(&self, domain: &str, port: u16) -> bool

Check if network access to a specific domain:port is allowed.

Source

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

Check if read access to a path is allowed under this policy.

Source

pub fn resource_limits(&self) -> ResourceLimits

Get the resource limits for this policy.

Source

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

Check if a path is writable under this policy.

Source

pub fn description(&self) -> &'static str

Get a human-readable description of the policy.

Trait Implementations§

Source§

impl Clone for SandboxPolicy

Source§

fn clone(&self) -> SandboxPolicy

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 SandboxPolicy

Source§

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

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

impl Default for SandboxPolicy

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for SandboxPolicy

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 Eq for SandboxPolicy

Source§

impl PartialEq for SandboxPolicy

Source§

fn eq(&self, other: &SandboxPolicy) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for SandboxPolicy

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
Source§

impl StructuralPartialEq for SandboxPolicy

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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> 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