pub struct Sandbox { /* private fields */ }Expand description
The sandbox: compiled schemas + policy chain + budget spec.
Implementations§
Source§impl Sandbox
impl Sandbox
Sourcepub fn new(
config: SandboxConfig,
policies: Vec<Box<dyn PolicyEngine>>,
) -> Result<Self, String>
pub fn new( config: SandboxConfig, policies: Vec<Box<dyn PolicyEngine>>, ) -> Result<Self, String>
Build a sandbox, compiling every tool schema up front (a schema that fails to compile is a configuration error surfaced at boot, not a silently-skipped validation at request time).
Sourcepub fn check(
&self,
store: &dyn StateStore,
session: &str,
raw: &[u8],
) -> ToolVerdict
pub fn check( &self, store: &dyn StateStore, session: &str, raw: &[u8], ) -> ToolVerdict
Evaluate a raw MCP payload for session.
Sourcepub fn check_with_principal(
&self,
store: &dyn StateStore,
session: &str,
principal: Option<(&str, &BudgetSpec)>,
raw: &[u8],
) -> ToolVerdict
pub fn check_with_principal( &self, store: &dyn StateStore, session: &str, principal: Option<(&str, &BudgetSpec)>, raw: &[u8], ) -> ToolVerdict
Same as Self::check but layers a principal-scoped budget check
on top of the session-scoped one. When principal is Some(spec),
the tool call is refused unless BOTH ledgers admit the spend; the
principal ledger persists across every session belonging to the
same identity, which is what makes header-rotation attacks
(resetting the session bucket by minting a new session id)
visible.
The two ledgers commit independently: if the principal check
passes and the session check fails, the principal debit is
refunded on the same dimensions before returning. Both budgets
must use identical BudgetSpec shapes so the refund is exact.
Auto Trait Implementations§
impl Freeze for Sandbox
impl !RefUnwindSafe for Sandbox
impl Send for Sandbox
impl Sync for Sandbox
impl Unpin for Sandbox
impl UnsafeUnpin for Sandbox
impl !UnwindSafe for Sandbox
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more