| name | google-adk-code-executor |
| description | ADK code execution backends. Use when agents need to write and run Python code — BuiltIn, Container, VertexAI, GKE, or local executors. |
Google ADK — Code Executors
Overview
Code executors let agents write and execute Python code. ADK provides multiple backends with different isolation levels.
| Executor | Isolation | Use Case | Install |
|---|
BuiltInCodeExecutor | Gemini sandbox | Simple code tasks | google-adk |
UnsafeLocalCodeExecutor | None (local process) | Development only | google-adk |
ContainerCodeExecutor | Docker container | Self-hosted production | google-adk[extensions] |
VertexAiCodeExecutor | Google Cloud sandbox | Managed production | google-adk[extensions] |
GkeCodeExecutor | Kubernetes pod | GKE-based production | google-adk[extensions] |
AgentEngineSandboxCodeExecutor | Agent Engine | Vertex AI Agent Engine | google-adk[extensions] |
BuiltInCodeExecutor (Default)
Uses Gemini's built-in code execution capability. No additional setup.
from google.adk.agents import Agent
from google.adk.code_executors import BuiltInCodeExecutor
agent = Agent(
name="coder",
model="gemini-2.5-flash",
instruction="Write and execute Python code to solve problems.",
code_executor=BuiltInCodeExecutor(),
)
UnsafeLocalCodeExecutor (Development Only)
Executes code directly on the host machine. Never use in production.
from google.adk.code_executors import UnsafeLocalCodeExecutor
agent = Agent(
name="dev_coder",
model="gemini-2.5-flash",
instruction="Write and run Python code locally.",
code_executor=UnsafeLocalCodeExecutor(),
)
ContainerCodeExecutor (Docker)
Runs code inside a Docker container for isolation.
pip install google-adk[extensions]
from google.adk.code_executors import ContainerCodeExecutor
agent = Agent(
name="sandboxed_coder",
model="gemini-2.5-flash",
instruction="Write and execute code safely.",
code_executor=ContainerCodeExecutor(
image="python:3.11-slim",
packages=["pandas", "numpy"],
),
)
VertexAiCodeExecutor (Managed)
Google Cloud-managed sandbox. No container management needed.
pip install google-adk[extensions]
from google.adk.code_executors import VertexAiCodeExecutor
agent = Agent(
name="cloud_coder",
model="gemini-2.5-flash",
instruction="Write and execute code in a managed sandbox.",
code_executor=VertexAiCodeExecutor(
project="my-gcp-project",
location="us-central1",
),
)
GkeCodeExecutor (Kubernetes)
Executes code in a Kubernetes pod on GKE.
pip install google-adk[extensions]
from google.adk.code_executors import GkeCodeExecutor
agent = Agent(
name="gke_coder",
model="gemini-2.5-flash",
instruction="Execute code on the cluster.",
code_executor=GkeCodeExecutor(
cluster_name="my-cluster",
project="my-gcp-project",
location="us-central1",
),
)
AgentEngineSandboxCodeExecutor
For agents deployed to Vertex AI Agent Engine:
from google.adk.code_executors import AgentEngineSandboxCodeExecutor
agent = Agent(
name="engine_coder",
model="gemini-2.5-flash",
instruction="Execute code in the Agent Engine sandbox.",
code_executor=AgentEngineSandboxCodeExecutor(),
)
Choosing an Executor
| Requirement | Recommended Executor |
|---|
| Quick prototyping | BuiltInCodeExecutor |
| Local dev with full libraries | UnsafeLocalCodeExecutor |
| Self-hosted production | ContainerCodeExecutor |
| Google Cloud production | VertexAiCodeExecutor |
| GKE-based infrastructure | GkeCodeExecutor |
| Deployed to Agent Engine | AgentEngineSandboxCodeExecutor |
Key Rules
BuiltInCodeExecutor is the safest default — uses Gemini's built-in sandbox
UnsafeLocalCodeExecutor has NO isolation — code runs with full host access
- Production deployments should use Container, VertexAI, or GKE executors
- Extension executors require
pip install google-adk[extensions]
- Code executor is set on the agent, not the runner
- Only ONE code executor per agent (set via
code_executor field)
Related Skills
google-adk-llm-agent — Agent configuration (where code_executor is set)
google-adk-deploy — Production deployment considerations