#[non_exhaustive]pub struct Capabilities {
pub reads_fs: bool,
pub writes_fs: bool,
pub network: bool,
pub reads_clock: bool,
pub reads_env: bool,
pub uses_rng: bool,
pub max_steps: Option<u64>,
pub max_value_elements: Option<usize>,
}Expand description
Context-wide sandbox policy the host hands the evaluator. The per-bit
booleans are the capabilities the host grants; per-function
requirements live on NativeFnGate. A call goes through iff every
bit declared on the fn’s gate is also set here — there is no per-name
allowlist or global short-circuit, so a successful call proves that
every bit on its gate was granted.
Beyond the capability bits, this struct also carries the runtime
resource budgets (max_steps, max_value_elements) the evaluator
enforces. The analyzer’s static reachability check only reads the
capability bits and ignores the budgets, but they live on the same
struct so the evaluator’s Context keeps a single sandbox-policy
carrier (the budgets are Option<_> defaulting to “unbounded”, so a
Capabilities built purely for the analyzer is unaffected).
#[non_exhaustive]: future capability bits are added here without a
breaking semver bump. External callers should prefer constructing via
Capabilities::default / Capabilities::all_granted and mutating
fields rather than relying on field-order struct literals.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.reads_fs: boolFilesystem reads (host fn that calls std::fs::read*, also the
policy bit consulted by FilesystemModuleResolver).
writes_fs: boolFilesystem writes (host fn that calls std::fs::write* /
OpenOptions::write / create_dir* / remove_*).
network: boolNetwork access (sockets, HTTP clients, DNS).
reads_clock: boolWall / monotonic clock reads (SystemTime::now, Instant::now).
reads_env: boolProcess environment reads (std::env::var, args, etc.).
uses_rng: boolRandom number generation (any non-deterministic source).
max_steps: Option<u64>Maximum number of AST nodes to process before aborting. None
is unbounded. Consulted only by the evaluator; the analyzer
ignores it.
max_value_elements: Option<usize>Maximum number of elements in a single List or Dict. None is
unbounded. Consulted only by the evaluator; the analyzer ignores
it.
Implementations§
Source§impl Capabilities
impl Capabilities
Sourcepub fn all_granted() -> Self
pub fn all_granted() -> Self
Audit-visible “grant everything” preset: every capability bit
flipped, no step / value-size budget. The spec forbids an
implicit Context::trusted()-style shortcut; hosts that need
full grant must call this and read the resulting Capabilities
as data. See docs/zh/guide/spec.md §4.2.
Note: opening filesystem reads also requires installing a
non-rejecting FilesystemModuleResolver. The reads_fs flag is
the policy bit; the resolver is the machinery that enforces it.
Trait Implementations§
Source§impl Clone for Capabilities
impl Clone for Capabilities
Source§fn clone(&self) -> Capabilities
fn clone(&self) -> Capabilities
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more