Skip to main content

Crate adk_code

Crate adk_code 

Source
Expand description

§adk-code

First-class code execution substrate for ADK-Rust.

This crate provides a typed executor abstraction, a truthful sandbox capability model, and shared execution backends for agent tools, Studio code nodes, and generated projects.

§Overview

adk-code owns:

§Product Direction

The primary code-execution path is Rust-first:

  • Author Rust code
  • Execute it live in a sandbox via CodeExecutor
  • Export the same Rust body into generated projects

Secondary support includes embedded JavaScript for lightweight transforms, in-process Python through the Monty interpreter, and container-backed execution for broader multi-language isolation. WasmGuestExecutor validates WASM guest modules but does not run them.

§Quick Start

use adk_code::{
    ExecutionLanguage, ExecutionPayload, ExecutionRequest,
    ExecutionResult, ExecutionStatus, SandboxPolicy,
};

let request = ExecutionRequest {
    language: ExecutionLanguage::Rust,
    payload: ExecutionPayload::Source {
        code: r#"
fn run(input: serde_json::Value) -> serde_json::Value {
    serde_json::json!({ "greeting": "hello" })
}
"#.to_string(),
    },
    argv: vec![],
    stdin: None,
    input: None,
    sandbox: SandboxPolicy::strict_rust(),
    identity: None,
};

assert_eq!(request.language, ExecutionLanguage::Rust);

§Crate Relationships

  • Depends on adk-core for shared error types
  • adk-tool depends on this crate for language-preset tool wrappers
  • Container executors drop every capability, set no-new-privileges, and limit the container to DEFAULT_PIDS_LIMIT processes unless the config turns each off

Re-exports§

pub use diagnostics::RustDiagnostic;
pub use diagnostics::parse_diagnostics;
pub use embedded_python::HostFunction;
pub use embedded_python::HostFunctionError;
pub use embedded_python::MontyBuildError;
pub use embedded_python::MontyExecutorBuilder;
pub use embedded_python::MontyOneShotExecutor;
pub use embedded_python::MontyReplExecutor;
pub use embedded_python::PathAccess;
pub use harness::HARNESS_TEMPLATE;
pub use harness::validate_rust_source;
pub use vertex_sandbox::SandboxCodeExecutor;
pub use vertex_sandbox::VertexSandboxClient;
pub use vertex_sandbox::VertexSandboxConfig;
pub use vertex_sandbox::VertexSandboxTool;

Modules§

a2a_compat
A2A-compatible event mapping boundary for collaboration transport.
compat
Choosing between the two code-execution layers.
diagnostics
Rust compiler diagnostic parsing.
embedded_python
Embedded Python executors backed by the Pydantic Monty interpreter.
harness
Harness template and source validation for Rust code execution.
vertex_sandbox
Vertex AI Agent Engine sandbox client (sandboxEnvironments, v1beta1).

Structs§

ArtifactRef
Reference to an externally stored artifact.
BackendCapabilities
Capabilities that a backend can actually enforce.
CodeResult
Result of a successful RustExecutor::execute call.
CodeTool
A tool that executes code through language-specific pipelines.
CollaborationEvent
A typed collaboration event for cross-agent coordination in a shared workspace.
ContainerCommandExecutor
CLI-based container executor that shells out to docker run per execution.
ContainerConfig
Configuration for the CLI-based container command executor.
DockerConfig
Configuration for the Docker executor.
DockerExecutor
Persistent Docker-backed code execution environment.
EmbeddedJsExecutor
Secondary embedded JavaScript executor using boa_engine.
ExecutionMetadata
Execution metadata for telemetry, audit, and artifact correlation.
ExecutionRequest
A full execution request.
ExecutionResult
Structured result of a code execution.
RustExecutor
Rust-specific executor that compiles code through a check → build → execute pipeline and delegates execution to a SandboxBackend.
RustExecutorConfig
Configuration for the RustExecutor pipeline.
RustSandboxConfig
Configuration for the Rust sandbox executor.
RustSandboxExecutor
The flagship Rust-authored code execution backend.
SandboxPolicy
Sandbox policy describing the requested execution constraints.
WasmGuestConfig
Configuration for the WASM guest executor.
WasmGuestExecutor
Guest-module backend for precompiled .wasm modules.
Workspace
A shared project context for collaborative code generation and execution.
WorkspaceBuilder
Builder for constructing a Workspace with fluent configuration.
WorkspaceMetadata
Metadata about a workspace project and execution session.

Enums§

CodeError
Errors from the language-aware code pipeline (RustExecutor).
CollaborationEventKind
The kind of a collaboration event in a shared workspace.
EnvironmentPolicy
Environment variable access policy for sandboxed execution.
ExecutionError
Errors that can occur during code execution.
ExecutionIsolation
Backend isolation class.
ExecutionLanguage
Supported execution languages.
ExecutionPayload
The code or module to execute.
ExecutionStatus
Terminal status of an execution.
FilesystemPolicy
Filesystem access policy for sandboxed execution.
GuestModuleFormat
Format of a precompiled guest module.
NetworkPolicy
Network access policy for sandboxed execution.

Constants§

DEFAULT_PIDS_LIMIT
Default process limit for containers the executors create.

Traits§

CodeExecutor
Async trait for code execution backends.

Functions§

validate_policy
Validates that the backend can enforce the requested sandbox policy.
validate_request
Validates a full execution request against a backend’s capabilities.
validate_wasm_bytes
Validate that the bytes represent a valid WASM binary module.