Vertex AI Agent Engine Code Execution Architecture & Best Practices#
1. Executive Summary#
This document defines the architectural guidelines and design patterns for integrating Code Execution Sandboxes within the Agentic SOC ecosystem on Vertex AI Agent Engine (Reasoning Engine) using the Agent Development Kit (ADK).
Modern agentic systems require a balance across three distinct operational primitives:
Model Context Protocol (MCP): For standardized, federated connectivity to enterprise security systems (Chronicle SIEM, SOAR, Google Threat Intelligence, Security Command Center).
Code Execution Sandboxes (
AgentEngineSandboxCodeExecutor/VertexAiCodeExecutor): For heavy data manipulation, log analytics, statistical calculation, and multi-step computational reasoning in isolated cloud microVMs.Function Calling & Deterministic Actions: For stateful, high-impact security operations requiring Human-in-the-Loop (HITL) authorization.
graph TD
Alert([Security Alert / Case]) --> Orchestrator[SOC Multi-Agent Orchestrator]
subgraph "Federated Integration Layer (MCP)"
Orchestrator -->|Federated Tool Schema| MCP[MCP Security Servers]
MCP -->|Fetch Raw Logs & Cases| SIEM[(Chronicle SIEM / SOAR / GTI)]
end
subgraph "Analytics & Synthesis Layer (Sandbox)"
Orchestrator -->|Delegate Log Analytics| Hunter[Threat Hunter / Tier 2 Agent]
Hunter -->|Write & Run Python Code| Sandbox[Vertex AI Agent Engine Sandbox]
Sandbox -->|Execute in MicroVM / gVisor| PythonRuntime[Python Runtime: Pandas, Regex, Math]
PythonRuntime -->|Return Compact Statistical Summary| Hunter
end
subgraph "Remediation Layer (Deterministic HITL)"
Hunter -->|Recommend Mitigation| HITL[Human-in-the-Loop Approval]
HITL -->|Approved Action| SOARAction[SOAR Containment Playbook]
end
2. Decision Matrix: Code Execution vs. MCP vs. Function Calling#
Evaluation Dimension |
Code Execution Sandbox |
Model Context Protocol (MCP) |
Function Calling |
|---|---|---|---|
Primary Responsibility |
Large data crunching, algorithmic math, timeline sorting, and file analysis. |
System-of-record integration and cross-agent tool federation. |
Direct environment manipulation, client callbacks, and mutable actions. |
Context Window Consumption |
Ultra-Low (\(O(1)\) token overhead): Raw logs (e.g. 5,000 UDM events) stay in sandbox storage; only computed results return to model. |
High to Medium (\(O(N)\) tokens): Tool payloads are serialized into model context unless aggressively truncated. |
Medium: Tool arguments and returns occupy conversational turns. |
Roundtrips / Latency |
Single-Turn Execution: Model generates code, executes within sandbox, and produces answer in 1 cycle. |
Multi-Turn (\(N\) hops): Model requests tool \(\rightarrow\) client invokes \(\rightarrow\) model sees result \(\rightarrow\) next tool. |
Multi-Turn: Requires client callback loop for each execution. |
Statefulness |
Stateful: Loaded dataframes, variables, and modules persist across turns in the session. |
Stateless: Each tool call is an independent request. |
Stateless: Handled by application layer. |
Security Boundary |
Isolated Cloud Sandbox (MicroVM / gVisor) with default-deny egress and memory limits. |
Standard process-level isolation (stdio) or HTTP/SSE network endpoints. |
Host process memory. |
Representative SOC Tasks |
- Calculating beaconing periodicity and jitter. |
- Querying Chronicle SIEM via |
- Requesting Human-in-the-Loop containment approval. |
3. ADK Code Executor Implementations on Google Cloud#
Class Name |
Runtime Environment |
Isolation Level |
Recommended Usage |
|---|---|---|---|
|
Vertex AI Agent Engine ( |
Managed cloud microVM (VPC-SC compliant) |
Primary Production Choice for Agent Engine deployments. |
|
Vertex AI Code Interpreter Extension |
Managed sandbox with pre-installed data science packages |
Enterprise analytics and data visualization. |
|
Native Gemini API server-side execution |
Model provider sandbox |
Fast prototyping and stateless execution fallback. |
|
Docker container ( |
Container isolation |
Hardened self-hosted environments. |
|
Local host Python subprocess |
None |
Hermetic unit testing only. |
4. Threat Hunter Integration Pattern: “Code Over Tools”#
In the Agentic SOC architecture, the Threat Hunter specialist analyzes large volumes of Chronicle UDM events. The hybrid “Code Over Tools” pattern operates as follows:
Query & Capture: Threat Hunter queries Chronicle SIEM via MCP (
search_security_events).File Staging: Rather than injecting 10,000 raw lines of JSON into the LLM prompt, telemetry is formatted as an input file (
udm_events.jsonornetwork_flows.csv) mounted directly to the sandbox.Targeted Python Processing: The agent writes a targeted Python script to extract statistics:
import json import pandas as pd import numpy as np # Load staged UDM events with open('udm_events.json') as f: events = json.load(f) df = pd.DataFrame([e['metadata'] for e in events if 'metadata' in e]) # Calculate inter-arrival time standard deviation for beaconing detection ...
Focused Synthesis: The agent receives only the final computed statistics or anomalies and generates a structured hunting report.
5. Advanced SecOps Sandbox Primitives (Cloud Run Sandboxes Pattern)#
Inspired by Google Cloud Run Sandboxes architecture (04-secops-payload-detonator and 01-hello-sandbox-101), the Threat Hunter agent incorporates two critical security capabilities:
A. Untrusted Dropper Detonation & Differential Filesystem Forensics#
Function:
detonate_and_capture_forensics(payload, payload_type="bash"|"python", timeout_sec=15, custom_workdir=None)Mechanism:
Snapshots baseline filesystem state in an isolated directory.
Executes untrusted shell stagers, droppers, or unpacking scripts with strict timeouts and stripped environments.
Performs pre/post directory diffing to extract dropped binaries, secondary payloads, or encrypted ransomware artifacts.
Computes SHA-256 cryptographic hashes, size metrics, and text previews for all generated artifacts.
Evaluates containment signals (blocked egress, C2 denial, GCP metadata server protection).
B. Zero-Trust Sandbox Isolation & Credential Shielding Audit#
Function:
verify_sandbox_containment(metadata_ip="169.254.169.254", forbidden_env_keys=None)Mechanism:
GCP Metadata Shielding: Probes
169.254.169.254instance endpoints to ensure compute metadata and workload identity tokens are unreachable from inside the sandbox.Credential Sanitization: Audits process environment variables against sensitive tokens (
CHRONICLE_SERVICE_ACCOUNT_PATH,GTI_API_KEY,SOAR_APP_KEY,HOST_SUPER_SECRET).Default-Deny Egress: Verifies outbound socket attempts to non-routable external test destinations (RFC 5737 TEST-NET-2
198.51.100.1) fail with connection timeout or network refusal.Returns a hardened zero-trust security verdict.