Skip to main content

adk_code/
lib.rs

1//! # adk-code
2//!
3//! First-class code execution substrate for ADK-Rust.
4//!
5//! This crate provides a typed executor abstraction, a truthful sandbox capability model,
6//! and shared execution backends for agent tools, Studio code nodes, and generated projects.
7//!
8//! ## Overview
9//!
10//! `adk-code` owns:
11//!
12//! - Execution request and result types ([`ExecutionRequest`], [`ExecutionResult`])
13//! - Backend interface ([`CodeExecutor`] trait)
14//! - Sandbox policy model ([`SandboxPolicy`], [`BackendCapabilities`])
15//! - Request validation helpers ([`validate_policy`], [`validate_request`])
16//! - Workspace abstraction for collaborative project builds ([`Workspace`], [`CollaborationEvent`])
17//! - Built-in execution backends: host-local Rust ([`RustSandboxExecutor`]), Rust over an
18//!   `adk-sandbox` backend ([`RustExecutor`], [`CodeTool`]), container execution
19//!   ([`ContainerCommandExecutor`], and `DockerExecutor` with the `docker` feature), embedded
20//!   JavaScript (`embedded-js`), embedded Python via Monty (`embedded-python`), and Vertex AI
21//!   Agent Engine sandboxes (`vertex-sandbox`)
22//!
23//! ## Product Direction
24//!
25//! The primary code-execution path is Rust-first:
26//!
27//! - Author Rust code
28//! - Execute it live in a sandbox via [`CodeExecutor`]
29//! - Export the same Rust body into generated projects
30//!
31//! Secondary support includes embedded JavaScript for lightweight transforms,
32//! in-process Python through the Monty interpreter, and container-backed
33//! execution for broader multi-language isolation. [`WasmGuestExecutor`] validates
34//! WASM guest modules but does not run them.
35//!
36//! ## Quick Start
37//!
38//! ```rust
39//! use adk_code::{
40//!     ExecutionLanguage, ExecutionPayload, ExecutionRequest,
41//!     ExecutionResult, ExecutionStatus, SandboxPolicy,
42//! };
43//!
44//! let request = ExecutionRequest {
45//!     language: ExecutionLanguage::Rust,
46//!     payload: ExecutionPayload::Source {
47//!         code: r#"
48//! fn run(input: serde_json::Value) -> serde_json::Value {
49//!     serde_json::json!({ "greeting": "hello" })
50//! }
51//! "#.to_string(),
52//!     },
53//!     argv: vec![],
54//!     stdin: None,
55//!     input: None,
56//!     sandbox: SandboxPolicy::strict_rust(),
57//!     identity: None,
58//! };
59//!
60//! assert_eq!(request.language, ExecutionLanguage::Rust);
61//! ```
62//!
63//! ## Crate Relationships
64//!
65//! - Depends on `adk-core` for shared error types
66//! - `adk-tool` depends on this crate for language-preset tool wrappers
67//! - Container executors drop every capability, set `no-new-privileges`, and limit the
68//!   container to [`DEFAULT_PIDS_LIMIT`] processes unless the config turns each off
69
70pub mod a2a_compat;
71mod code_tool;
72pub mod compat;
73mod container;
74pub mod diagnostics;
75#[cfg(feature = "embedded-js")]
76mod embedded_js;
77#[cfg(feature = "embedded-python")]
78pub mod embedded_python;
79mod error;
80mod executor;
81pub mod harness;
82mod host_process;
83mod rust_executor;
84mod rust_sandbox;
85mod types;
86#[cfg(feature = "vertex-sandbox")]
87pub mod vertex_sandbox;
88mod wasm_guest;
89mod workspace;
90
91pub use code_tool::CodeTool;
92#[cfg(feature = "docker")]
93pub use container::DockerExecutor;
94pub use container::*;
95pub use diagnostics::{RustDiagnostic, parse_diagnostics};
96#[cfg(feature = "embedded-js")]
97pub use embedded_js::*;
98#[cfg(feature = "embedded-python")]
99pub use embedded_python::{
100    HostFunction, HostFunctionError, MontyBuildError, MontyExecutorBuilder, MontyOneShotExecutor,
101    MontyReplExecutor, PathAccess,
102};
103pub use error::*;
104pub use executor::*;
105pub use harness::{HARNESS_TEMPLATE, validate_rust_source};
106pub use rust_executor::{CodeResult, RustExecutor, RustExecutorConfig};
107pub use rust_sandbox::*;
108pub use types::*;
109#[cfg(feature = "vertex-sandbox")]
110pub use vertex_sandbox::{
111    SandboxCodeExecutor, VertexSandboxClient, VertexSandboxConfig, VertexSandboxTool,
112};
113pub use wasm_guest::*;
114pub use workspace::*;