Skip to main content

Module vertex_sandbox

Module vertex_sandbox 

Source
Expand description

Vertex AI Agent Engine sandbox client (sandboxEnvironments, v1beta1).

A managed code-execution sandbox lives under a reasoning engine at projects/*/locations/*/reasoningEngines/*/sandboxEnvironments/*. This module provides:

  • VertexSandboxClient — the REST surface: create (LRO), get, list, delete (LRO), and the synchronous :execute method, plus execute_code implementing the chunk conventions shared with adk-python and the Vertex AI SDK.
  • SandboxCodeExecutor — adk-python AgentEngineSandboxCodeExecutor parity: per-session lazy sandbox creation with recreate-on-not-running semantics.
  • VertexSandboxTool — an adk_core::Tool exposing sandbox code execution to LLM agents, keyed by the calling session.

Transport, credential caching, LRO polling, and scope validation come from adk_gcp.

§Chunk conventions

:execute exchanges opaque Chunk values. The code-execution conventions over them (adk-python/SDK parity):

ChunkmimeTypedata (base64 of)metadata.attributes
Code inputapplication/json{"code": "<source>"}—
Input filethe file’s MIME typeraw bytesfile_name = base64(filename)
Console outputapplication/json{"msg_out": ..., "msg_err": ...}no file_name
Output filemay be absentraw bytesfile_name = base64(filename)

Files are limited to 100 MB per request and per response. The request side is enforced before sending; the response side is bounded by the client’s response-size limit (140 MiB, covering base64 overhead).

§Example

use adk_code::vertex_sandbox::{
    CreateSandboxRequest, VertexSandboxClient, VertexSandboxConfig,
};

let config = VertexSandboxConfig::new("my-project", "us-central1");
let client = VertexSandboxClient::new_with_adc(config)?;

let sandbox = client
    .create_sandbox("4242", CreateSandboxRequest::new("my-sandbox"))
    .await?;
let name = sandbox.name.expect("created sandbox has a name");

let result = client.execute_code(&name, "print('hello')", &[]).await?;
assert_eq!(result.stdout, "hello\n");

client.delete_sandbox(&name).await?;

Structs§

Chunk
One unit of :execute input or output.
ChunkMetadata
Optional metadata carried by a Chunk.
CodeExecutionEnvironment
Spec of a code-execution sandbox environment.
ComputerUseEnvironment
Spec of a computer-use sandbox environment (no fields).
CreateSandboxRequest
Input to create_sandbox.
InputFile
An input file for execute_code.
OutputFile
A file the executed code wrote.
SandboxCodeExecutor
Executes code in Agent Engine sandboxes with per-session lifecycle management, matching adk-python’s AgentEngineSandboxCodeExecutor.
SandboxEnvironment
A SandboxEnvironment wire resource.
SandboxEnvironmentSpec
The sandbox_environment_category oneof: exactly one category is set.
SandboxExecutionResult
Decoded result of one code execution.
VertexSandboxClient
Client for Agent Engine sandbox environments.
VertexSandboxConfig
Configuration for VertexSandboxClient.
VertexSandboxTool
A tool that executes model-written code in a managed Vertex AI Agent Engine sandbox.

Enums§

CodeLanguage
Language runtime of a code-execution sandbox.
MachineConfig
Machine shape of a code-execution sandbox.
SandboxState
Lifecycle state of a sandbox environment (output only).

Constants§

DEFAULT_SANDBOX_DISPLAY_NAME
Display name SandboxCodeExecutor uses for lazily created sandboxes (adk-python parity).
DEFAULT_SANDBOX_TTL
TTL SandboxCodeExecutor sends for lazily created sandboxes: one year, matching adk-python.
MAX_REQUEST_FILE_BYTES
Maximum raw file bytes accepted per :execute request (100 MB).

Functions§

decode_output_chunks
Decodes :execute output chunks into stdout, stderr, and output files.
encode_code_chunk
Encodes source code as the code-input chunk.
encode_file_chunk
Encodes an input file as a file chunk (file_name attribute set).