Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0c4d3f5
[06/24] Add gke_code_executor.py
syangx39 Jun 24, 2025
f28f4b7
[06/24] Add gke_code_executor.py
syangx39 Jun 24, 2025
760fb7f
[06/24] Add gke_code_executor.py
syangx39 Jun 24, 2025
6b0e772
[06/24] Add gke_code_executor.py
syangx39 Jun 24, 2025
33446f8
[07/10] Add deployemnt_rbac.yaml into samples folder
syangx39 Jul 10, 2025
d09c319
[07/10] Add deployemnt_rbac.yaml into samples folder
syangx39 Jul 10, 2025
1f06fe1
[07/10] Add deployemnt_rbac.yaml into samples folder
syangx39 Jul 10, 2025
254bdcb
[07/10] Make cpu/memory requests configurable
syangx39 Jul 10, 2025
285b53a
[07/10] Add annotation
syangx39 Jul 11, 2025
6a93e12
[07/10] Raise error in _get_pod_logs()
syangx39 Jul 11, 2025
2b16d7b
[07/10] Add owner_reference
syangx39 Jul 11, 2025
9982d39
[07/10] Add owner_reference
syangx39 Jul 11, 2025
6685f63
[07/25] add the sample
syangx39 Jul 25, 2025
efd7a76
[07/25] modify pyproject.toml to add gke-specific dependency
syangx39 Jul 25, 2025
6914958
[08/15] rename cpu_request
syangx39 Aug 15, 2025
5b7595c
[08/15] rename cpu_request
syangx39 Aug 15, 2025
1a6eca2
[08/15] rename cpu_request
syangx39 Aug 15, 2025
6010a3b
[08/25] Modify ADK
syangx39 Aug 25, 2025
4dc4753
[08/25] Modify ADK
syangx39 Aug 25, 2025
9ec5e8b
[08/25] Modify ADK
syangx39 Aug 25, 2025
3c962ff
[08/25] Modify ADK
syangx39 Aug 25, 2025
ae13800
[08/25] Modify ADK
syangx39 Aug 25, 2025
d3c1dd0
[08/25] Modify ADK
syangx39 Aug 25, 2025
67ebf38
[08/28] fix kubeconfig
syangx39 Aug 28, 2025
5a7002a
fix(gke): add future annotations for py3.9 compatibility #non-breaking
GWeale Sep 6, 2025
7b40d22
fix(gke_code_executor): add annotations to the fil
GWeale Sep 6, 2025
2049d68
style(gke): use relative imports; no cli imports #non-breaking
GWeale Sep 6, 2025
adb2ad4
style(gke): make imports relative; avoid cli import pattern #non-brea…
GWeale Sep 6, 2025
75814e9
test(gke): expose client/config for monkeypatch; fix imports #non-bre…
GWeale Sep 6, 2025
cd6d518
chore(pyproject): keep-sorted ordering for kubernetes entries #non-br…
GWeale Sep 6, 2025
3f57383
Merge branch 'main' into main
GWeale Sep 6, 2025
869ae1a
Merge branch 'main' into main
hangfei Sep 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions contributing/samples/code_execution/gke_sandbox_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""A Python coding agent using the GkeCodeExecutor for secure execution."""

from google.adk.agents import LlmAgent
from google.adk.code_executors import GkeCodeExecutor


def gke_agent_system_instruction():
"""Returns: The system instruction for the GKE-based coding agent."""
return """You are a helpful and capable AI agent that can write and execute Python code to answer questions and perform tasks.

When a user asks a question, follow these steps:
1. Analyze the request.
2. Write a complete, self-contained Python script to accomplish the task.
3. Your code will be executed in a secure, sandboxed environment.
4. Return the full and complete output from the code execution, including any text, results, or error messages."""


gke_executor = GkeCodeExecutor(
# This must match the namespace in your deployment_rbac.yaml where the
# agent's ServiceAccount and Role have permissions.
namespace="agent-sandbox",
# Setting an explicit timeout prevents a stuck job from running forever.
timeout_seconds=600,
)

root_agent = LlmAgent(
name="gke_coding_agent",
model="gemini-2.0-flash",
description=(
"A general-purpose agent that executes Python code in a secure GKE"
" Sandbox."
),
instruction=gke_agent_system_instruction(),
code_executor=gke_executor,
)
50 changes: 50 additions & 0 deletions contributing/samples/gke_agent_sandbox/deployment_rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
apiVersion: v1
kind: Namespace
metadata:
name: agent-sandbox
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: adk-agent-sa
namespace: agent-sandbox
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: adk-agent-role
namespace: agent-sandbox
rules:
- apiGroups: ["batch"]
resources: ["jobs"]
# create: Needed for _batch_v1.create_namespaced_job().
# watch: Needed for watch.stream(self._batch_v1.list_namespaced_job, ...) to wait for completion
# list/get: Required for the watch to initialize and to get job details.
verbs: ["create", "get", "watch", "list", "delete"]
- apiGroups: [""]
resources: ["configmaps"]
# create: Needed mount the agent's code into the Job's Pod.
# delete: Needed for cleanup in the finally block
verbs: ["create", "get", "list", "delete"]
- apiGroups: [""]
resources: ["pods"]
# list: Needed to find the correct Pod _core_v1.list_namespaced_pod(label_selector=...)
verbs: ["get", "list", "delete"]
- apiGroups: [""]
# get: Needed for _core_v1.read_namespaced_pod_log() to get the code execution results and logs.
resources: ["pods/log"]
verbs: ["get", "list"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: adk-agent-binding
namespace: agent-sandbox
subjects:
- kind: ServiceAccount
name: adk-agent-sa
namespace: agent-sandbox
roleRef:
kind: Role
name: adk-agent-role
apiGroup: rbac.authorization.k8s.io
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,13 @@ test = [
"langchain-community>=0.3.17",
"langgraph>=0.2.60, <= 0.4.10", # For LangGraphAgent
"litellm>=1.75.5, <2.0.0", # For LiteLLM tests
"kubernetes>=29.0.0", # For GkeCodeExecutor
"llama-index-readers-file>=0.4.0", # For retrieval tests
"openai>=1.100.2", # For LiteLLM
"pytest>=8.3.4",
"pytest-asyncio>=0.25.0",
"pytest-mock>=3.14.0",
"pytest-xdist>=3.6.1",
"pytest>=8.3.4",
"python-multipart>=0.0.9",
"rouge-score>=0.1.2",
"tabulate>=0.9.0",
Expand All @@ -139,6 +140,7 @@ extensions = [
"docker>=7.0.0", # For ContainerCodeExecutor
"langgraph>=0.2.60", # For LangGraphAgent
"litellm>=1.75.5", # For LiteLlm class. Currently has OpenAI limitations. TODO: once LiteLlm fix it
"kubernetes>=29.0.0", # For GkeCodeExecutor
"llama-index-readers-file>=0.4.0", # For retrieval using LlamaIndex.
"llama-index-embeddings-google-genai>=0.3.0",# For files retrieval using LlamaIndex.
"lxml>=5.3.0", # For load_web_page tool.
Expand Down
11 changes: 11 additions & 0 deletions src/google/adk/code_executors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
'UnsafeLocalCodeExecutor',
'VertexAiCodeExecutor',
'ContainerCodeExecutor',
'GkeCodeExecutor',
]


Expand All @@ -52,4 +53,14 @@ def __getattr__(name: str):
'ContainerCodeExecutor requires additional dependencies. '
'Please install with: pip install "google-adk[extensions]"'
) from e
elif name == 'GkeCodeExecutor':
try:
from .gke_code_executor import GkeCodeExecutor

return GkeCodeExecutor
except ImportError as e:
raise ImportError(
'GkeCodeExecutor requires additional dependencies. '
'Please install with: pip install "google-adk[extensions]"'
) from e
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
Loading