pub struct Sandbox { /* private fields */ }Expand description
Executes modules in an isolated subprocess for security isolation.
When enabled is false, execution is performed in-process (no sandbox).
When enabled is true, a child process running sandbox_runner handles
the execution and communicates results via JSON over stdin/stdout.
Implementations§
Source§impl Sandbox
impl Sandbox
Sourcepub fn new(enabled: bool, timeout_secs: u64) -> Self
pub fn new(enabled: bool, timeout_secs: u64) -> Self
Create a new Sandbox.
§Arguments
enabled— enable subprocess isolationtimeout_secs— subprocess timeout in seconds (0 = use default 300 s)
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Return true when subprocess isolation is enabled.
Sourcepub async fn execute(
&self,
module_id: &str,
input_data: Value,
executor: &Executor,
) -> Result<Value, ModuleExecutionError>
pub async fn execute( &self, module_id: &str, input_data: Value, executor: &Executor, ) -> Result<Value, ModuleExecutionError>
Execute a module, optionally in an isolated subprocess.
§Arguments
module_id— identifier of the module to executeinput_data— JSON input for the module
Returns the module output as a serde_json::Value.
§Errors
Returns ModuleExecutionError on timeout, non-zero exit, or parse failure.
When enabled is false, delegates directly to executor.call() and
returns the result (or maps the apcore module error into a
ModuleExecutionError::SpawnFailed). This passthrough makes Sandbox
safe to call unconditionally from the dispatcher: callers no longer
need to branch on the --sandbox flag at every call site.
When enabled is true, runs module_id in an isolated subprocess
via sandbox_runner and returns the parsed JSON output. The executor
argument is intentionally unused in this branch — the subprocess loads
its own apcore environment from the inherited APCORE_* env vars.