pub struct RustExecutor { /* private fields */ }Expand description
Rust-specific executor that compiles code through a check → build → execute pipeline
and delegates execution to a SandboxBackend.
§Isolation
| Step | Where it runs | Environment |
|---|---|---|
| Check, build | Inside the backend when it confines filesystem reads and accepts Language::Command (Unix only); otherwise on the host | Cleared, plus the toolchain allowlist from ProcessBackend::toolchain_env |
| Execute | Inside the backend | Whatever the backend exposes; ProcessBackend clears it |
With the environment cleared, env! and option_env! in user code cannot
embed host credentials into the binary. Compile-time file access such as
include_str! reads with the permissions of wherever rustc runs: inside a
read-confining backend it is confined like the binary, and on the host it
reaches no file the binary could not also read at run time, because rustc
runs on the host only when the backend does not confine reads. On Windows,
rustc always runs on the host.
§Example
use adk_code::{RustExecutor, RustExecutorConfig};
use adk_sandbox::ProcessBackend;
use std::sync::Arc;
let backend = Arc::new(ProcessBackend::default());
let executor = RustExecutor::new(backend, RustExecutorConfig::default());
let result = executor.execute("fn run(input: serde_json::Value) -> serde_json::Value { input }", None).await?;Implementations§
Source§impl RustExecutor
impl RustExecutor
Sourcepub fn new(backend: Arc<dyn SandboxBackend>, config: RustExecutorConfig) -> Self
pub fn new(backend: Arc<dyn SandboxBackend>, config: RustExecutorConfig) -> Self
Create a new executor with the given sandbox backend and configuration.
Sourcepub async fn execute(
&self,
code: &str,
input: Option<&Value>,
timeout: Duration,
) -> Result<CodeResult, CodeError>
pub async fn execute( &self, code: &str, input: Option<&Value>, timeout: Duration, ) -> Result<CodeResult, CodeError>
Execute Rust code through the check → build → execute pipeline.
The input parameter is optional JSON that will be serialized to stdin
for the harness run() function.
§Errors
CodeError::InvalidCodeif the source fails pre-compilation validationCodeError::CompileErrorif the check step finds error-level diagnosticsCodeError::DependencyNotFoundifserde_jsoncannot be locatedCodeError::Sandboxif the backend fails during execution