adk_code/compat.rs
1//! Choosing between the two code-execution layers.
2//!
3//! Code execution has two layers. Both are supported; neither is deprecated.
4//!
5//! | Layer | Backend trait | Request and result | Built on it |
6//! |-------|---------------|--------------------|-------------|
7//! | `adk-sandbox` | [`SandboxBackend`](adk_sandbox::SandboxBackend) | [`ExecRequest`](adk_sandbox::ExecRequest), [`ExecResult`](adk_sandbox::ExecResult) | [`RustExecutor`](crate::RustExecutor), [`CodeTool`](crate::CodeTool), `adk_sandbox::SandboxTool` |
8//! | `adk-code` | [`CodeExecutor`](crate::CodeExecutor) | [`ExecutionRequest`](crate::ExecutionRequest), [`ExecutionResult`](crate::ExecutionResult), with a [`SandboxPolicy`](crate::SandboxPolicy) | [`RustSandboxExecutor`](crate::RustSandboxExecutor), [`ContainerCommandExecutor`](crate::ContainerCommandExecutor), the embedded JavaScript and Monty executors, and `adk-tool`'s `PythonCodeTool` and `JavaScriptCodeTool` |
9//!
10//! ## Key API Differences
11//!
12//! ### `SandboxBackend` and `CodeExecutor`
13//!
14//! `CodeExecutor` has lifecycle methods (`start`, `stop`, `restart`, `is_running`), reports
15//! [`BackendCapabilities`](crate::BackendCapabilities), and takes an `ExecutionRequest` whose
16//! `SandboxPolicy` it validates against them. `SandboxBackend` is minimal:
17//! `execute(ExecRequest) -> Result<ExecResult, SandboxError>`, with isolation coming from
18//! the backend, such as a `ProcessBackend` under an OS enforcer.
19//!
20//! ### `ExecutionRequest` and `ExecRequest`
21//!
22//! `ExecutionRequest` has `payload` (an enum with `Source` and `GuestModule`), `sandbox`
23//! (the policy), `identity`, and `argv`. `ExecRequest` is flat: `language`, `code`,
24//! `stdin`, `timeout`, `memory_limit_mb`, `env`.
25//!
26//! ### `RustSandboxExecutor` and `RustExecutor`
27//!
28//! `RustSandboxExecutor` compiles and runs Rust as host processes. `RustExecutor` delegates
29//! execution to a `SandboxBackend`, separating compilation from isolation; construct it
30//! with `RustExecutor::new(backend, config)`.
31//!
32//! ## Removed
33//!
34//! `adk-tool`'s `RustCodeTool` was removed; [`CodeTool`](crate::CodeTool) replaces it.