Skip to main content

Module code_execution

Module code_execution 

Source
Available on crate features code and tools only.
Expand description

Code execution tools for ADK agents.

This module provides language-preset tool wrappers over the adk-code execution substrate. Each tool chooses a default backend and sandbox policy automatically.

§Available Tools

  • CodeTool — Recommended Rust code execution tool using RustExecutor + SandboxBackend.
  • FrontendCodeTool — Placeholder frontend preset for collaborative workspace examples.
  • JavaScriptCodeTool — Secondary scripting preset for lightweight transforms.
  • PythonCodeTool — Container-backed CPython execution preset (full Python ecosystem: pip packages, C extensions, complete standard library).
  • MontyPythonCodeTool — In-process Python execution via the Monty interpreter (one-shot or per-session REPL; no container required).

§Scope Model

Each tool declares the authorization scopes it requires via Tool::required_scopes(). When a ScopeGuard (from adk_auth) is active, the framework checks that the calling user possesses all declared scopes before dispatching execution.

ToolRequired ScopesRationale
CodeToolcode:execute, code:execute:rustSandboxed Rust execution with strict defaults
JavaScriptCodeToolcode:executeIn-process embedded JS, no elevated access
PythonCodeToolcode:execute, code:execute:containerContainer-backed, elevated mode
MontyPythonCodeToolcode:executeIn-process Monty interpreter, host-granted OS access only
FrontendCodeToolcode:execute, code:execute:containerContainer-backed, elevated mode

§Elevated Modes and Confirmation

Certain execution modes go beyond the base scope and should be gated by additional scopes and/or the ADK confirmation flow:

  • Host execution (code:execute:host): Runs on the local host without container isolation. Confirmation is required unless explicitly disabled by the deployer.
  • Container execution (code:execute:container): Spawns an isolated container. Deployers should consider confirmation gating.
  • Network access (code:network): Enables outbound network from the execution environment. Confirmation is strongly recommended.
  • Writable filesystem (code:filesystem:write): Grants write access beyond the default read-only sandbox. Confirmation is strongly recommended.

Generic command execution should not silently inherit the trust posture of the Rust sandbox preset.

§Quick Start

use adk_tool::{
    CodeTool, FrontendCodeTool, JavaScriptCodeTool, MontyPythonCodeTool, PythonCodeTool,
};
use std::sync::Arc;

// Rust code execution (recommended)
let rust_tool = Arc::new(CodeTool::new());

// Frontend specialist (placeholder until container backend ships)
let frontend_tool = Arc::new(FrontendCodeTool::react());

// Lightweight JS transforms (requires the `code-embedded-js` feature)
let js_tool = Arc::new(JavaScriptCodeTool::new());

// Container-backed CPython execution
let py_tool = Arc::new(PythonCodeTool::new());

// In-process Python execution (requires the `code-embedded-python` feature)
let monty_tool = Arc::new(MontyPythonCodeTool::new());

Structs§

CodeTool
A tool that executes code through language-specific pipelines.
FrontendCodeTool
Container-backed frontend code execution tool.
JavaScriptCodeTool
Embedded JavaScript code execution tool.
MontyPythonCodeTool
Embedded Python code execution tool backed by the Monty interpreter.
MontyPythonCodeToolBuilder
Configures a MontyPythonCodeTool: OS-access grants, host functions, and limits are forwarded to MontyExecutorBuilder; the terminal methods select the mode.
PythonCodeTool
Container-backed Python code execution tool.