Skip to main content

adk_tool/code_execution/
mod.rs

1//! Code execution tools for ADK agents.
2//!
3//! This module provides language-preset tool wrappers over the `adk-code` execution
4//! substrate. Each tool chooses a default backend and sandbox policy automatically.
5//!
6//! ## Available Tools
7//!
8//! - [`CodeTool`] — Recommended Rust code execution tool using `RustExecutor` + `SandboxBackend`.
9//! - [`FrontendCodeTool`] — Placeholder frontend preset for collaborative workspace examples.
10//! - [`JavaScriptCodeTool`] — Secondary scripting preset for lightweight transforms.
11//! - [`PythonCodeTool`] — Container-backed CPython execution preset (full Python
12//!   ecosystem: pip packages, C extensions, complete standard library).
13//! - [`MontyPythonCodeTool`] — In-process Python execution via the Monty
14//!   interpreter (one-shot or per-session REPL; no container required).
15//!
16//! ## Scope Model
17//!
18//! Each tool declares the authorization scopes it requires via
19//! `Tool::required_scopes()`.  When a `ScopeGuard` (from `adk_auth`)
20//! is active, the framework checks that the calling user possesses **all**
21//! declared scopes before dispatching execution.
22//!
23//! | Tool | Required Scopes | Rationale |
24//! |------|----------------|-----------|
25//! | [`CodeTool`] | `code:execute`, `code:execute:rust` | Sandboxed Rust execution with strict defaults |
26//! | [`JavaScriptCodeTool`] | `code:execute` | In-process embedded JS, no elevated access |
27//! | [`PythonCodeTool`] | `code:execute`, `code:execute:container` | Container-backed, elevated mode |
28//! | [`MontyPythonCodeTool`] | `code:execute` | In-process Monty interpreter, host-granted OS access only |
29//! | [`FrontendCodeTool`] | `code:execute`, `code:execute:container` | Container-backed, elevated mode |
30//!
31//! ### Elevated Modes and Confirmation
32//!
33//! Certain execution modes go beyond the base scope and should be gated by
34//! additional scopes and/or the ADK confirmation flow:
35//!
36//! - **Host execution** (`code:execute:host`): Runs on the local host without
37//!   container isolation.  Confirmation is required unless explicitly disabled
38//!   by the deployer.
39//! - **Container execution** (`code:execute:container`): Spawns an isolated
40//!   container.  Deployers should consider confirmation gating.
41//! - **Network access** (`code:network`): Enables outbound network from the
42//!   execution environment.  Confirmation is strongly recommended.
43//! - **Writable filesystem** (`code:filesystem:write`): Grants write access
44//!   beyond the default read-only sandbox.  Confirmation is strongly
45//!   recommended.
46//!
47//! Generic command execution should **not** silently inherit the trust posture
48//! of the Rust sandbox preset.
49//!
50//! ## Quick Start
51//!
52//! ```rust
53//! use adk_code::{RustExecutor, RustExecutorConfig};
54//! use adk_sandbox::ProcessBackend;
55//! use adk_tool::{
56//!     CodeTool, FrontendCodeTool, JavaScriptCodeTool, MontyPythonCodeTool, PythonCodeTool,
57//! };
58//! use std::sync::Arc;
59//!
60//! // Rust code execution (recommended): compiles and runs through a sandbox backend
61//! let backend = Arc::new(ProcessBackend::default());
62//! let rust_tool = Arc::new(CodeTool::new(RustExecutor::new(backend, RustExecutorConfig::default())));
63//!
64//! // Frontend specialist (placeholder until container backend ships)
65//! let frontend_tool = Arc::new(FrontendCodeTool::react());
66//!
67//! // Lightweight JS transforms (requires the `code-embedded-js` feature)
68//! let js_tool = Arc::new(JavaScriptCodeTool::new());
69//!
70//! // Container-backed CPython execution
71//! let py_tool = Arc::new(PythonCodeTool::new());
72//!
73//! // In-process Python execution (requires the `code-embedded-python` feature)
74//! let monty_tool = Arc::new(MontyPythonCodeTool::new());
75//! ```
76
77mod frontend_code_tool;
78mod javascript_code_tool;
79mod monty_python_code_tool;
80mod python_code_tool;
81
82pub use frontend_code_tool::FrontendCodeTool;
83pub use javascript_code_tool::JavaScriptCodeTool;
84pub use monty_python_code_tool::MontyPythonCodeTool;
85#[cfg(feature = "code-embedded-python")]
86pub use monty_python_code_tool::MontyPythonCodeToolBuilder;
87pub use python_code_tool::PythonCodeTool;
88
89/// Re-export [`adk_code::CodeTool`] as the recommended code execution tool.
90#[cfg(feature = "code")]
91pub use adk_code::CodeTool;