adk-sandbox
Isolated code execution runtime for ADK-Rust agents.
adk-sandbox provides the SandboxBackend trait and two implementations for executing code in isolation. It separates the isolation concern from language-specific toolchains — adk-code handles compilation and language pipelines, while adk-sandbox handles running the resulting code safely.
Feature Flags
| Feature | Description | Default | Extra Dependencies |
|---|---|---|---|
process |
Subprocess execution via tokio::process |
✅ | None (uses tokio) |
wasm |
In-process WASM execution via wasmtime |
❌ | wasmtime, wasmtime-wasi |
Backend Comparison
| Capability | ProcessBackend |
WasmBackend |
|---|---|---|
| Timeout enforcement | ✅ tokio::time::timeout |
✅ Epoch-based interruption |
| Memory limit | ❌ Not enforced | ✅ StoreLimitsBuilder |
| Network isolation | ❌ Not enforced | ✅ No WASI network |
| Filesystem isolation | ❌ Not enforced | ✅ No WASI preopens |
| Environment isolation | ✅ env_clear() + explicit env |
✅ Full (no host access) |
| Output truncation | ✅ 1 MB limit, UTF-8 safe | ✅ 1 MB capture pipes |
| Supported languages | Rust, Python, JS, TS, Command | Wasm only |
ProcessBackend is honest about what it does not enforce. Use WasmBackend when you need full sandboxing with memory limits and no host access.
Quick Start
use ;
use Duration;
use HashMap;
async
Note: ExecRequest has no Default implementation — timeout must always be set explicitly.
SandboxTool (Agent Integration)
SandboxTool implements adk_core::Tool, making sandbox execution available to LLM agents. Errors are returned as structured JSON (never as ToolError), so the agent can reason about failures.
use ;
use Arc;
let backend = new;
let tool = new;
// Use with any LLM agent
let agent = new
.tool
.build?;
The tool accepts language, code, optional stdin, and optional timeout_secs parameters. It requires the code:execute scope.
Error Handling
All backend errors use SandboxError:
| Variant | When |
|---|---|
Timeout |
Execution exceeded the configured timeout |
MemoryExceeded |
WASM module exceeded memory limit |
ExecutionFailed |
Internal error (I/O, spawn failure) |
InvalidRequest |
Unsupported language for this backend |
BackendUnavailable |
Missing runtime or feature not enabled |
Non-zero exit codes are not errors — they are returned in ExecResult.exit_code.
License
Apache-2.0