Skip to content

Commit d9247be

Browse files
committed
Correct format for the failed format checks.
1 parent 9d1fd94 commit d9247be

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

src/google/adk/code_executors/gke_code_executor.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import uuid
1919

2020
from agentic_sandbox import SandboxClient
21-
2221
import kubernetes as k8s
2322
from kubernetes.watch import Watch
2423

@@ -92,7 +91,7 @@ class GkeCodeExecutor(BaseCodeExecutor):
9291

9392
kubeconfig_path: str | None = None
9493
kubeconfig_context: str | None = None
95-
94+
9695
# Sandbox constants
9796
sandbox_template: str = "python-sandbox-template"
9897

@@ -122,9 +121,10 @@ def __init__(
122121
self.kubeconfig_path = kubeconfig_path
123122
self.kubeconfig_context = kubeconfig_context
124123

125-
if executor_type not in ['job', 'sandbox']:
124+
if executor_type not in ["job", "sandbox"]:
126125
raise ValueError(
127-
f"Invalid executor_type: '{executor_type}'. Must be 'job' or 'sandbox'."
126+
f"Invalid executor_type: '{executor_type}'. Must be 'job' or"
127+
" 'sandbox'."
128128
)
129129
if self.kubeconfig_path:
130130
try:
@@ -166,24 +166,26 @@ def __init__(
166166
def _execute_in_sandbox(self, code: str) -> CodeExecutionResult:
167167
"""Executes code using Agent Sandbox Client."""
168168
try:
169-
with SandboxClient(
170-
template_name=self.sandbox_template,
171-
gateway_name=self.sandbox_gateway_name,
172-
namespace=self.namespace
173-
) as sandbox:
174-
# Execute the code as a python script
175-
logger.debug("Executing code in sandbox:\n```\n%s\n```", code)
176-
sandbox.write("script.py", code)
177-
result = sandbox.run("python3 script.py")
178-
179-
return CodeExecutionResult(stdout=result.stdout)
169+
with SandboxClient(
170+
template_name=self.sandbox_template,
171+
gateway_name=self.sandbox_gateway_name,
172+
namespace=self.namespace,
173+
) as sandbox:
174+
# Execute the code as a python script
175+
logger.debug("Executing code in sandbox:\n```\n%s\n```", code)
176+
sandbox.write("script.py", code)
177+
result = sandbox.run("python3 script.py")
178+
179+
return CodeExecutionResult(stdout=result.stdout)
180180
except Exception as e:
181-
logger.error("Sandbox execution failed", exc_info=True)
182-
return CodeExecutionResult(
183-
stderr=f"Sandbox execution failed: {str(e)}",
184-
)
181+
logger.error("Sandbox execution failed", exc_info=True)
182+
return CodeExecutionResult(
183+
stderr=f"Sandbox execution failed: {str(e)}",
184+
)
185185

186-
def _execute_as_job(self, code: str, invocation_context: InvocationContext) -> CodeExecutionResult:
186+
def _execute_as_job(
187+
self, code: str, invocation_context: InvocationContext
188+
) -> CodeExecutionResult:
187189
"""Orchestrates the secure execution of a code snippet on GKE."""
188190
job_name = f"adk-exec-{uuid.uuid4().hex[:10]}"
189191
configmap_name = f"code-src-{job_name}"
@@ -234,14 +236,13 @@ def execute_code(
234236
invocation_context: InvocationContext,
235237
code_execution_input: CodeExecutionInput,
236238
) -> CodeExecutionResult:
237-
238239
"""Overrides the base method to route execution based on executor_type."""
239240
code = code_execution_input.code
240241
if self.executor_type == "sandbox":
241-
return self._execute_in_sandbox(code)
242+
return self._execute_in_sandbox(code)
242243
else:
243-
# Fallback to existing GKE Job logic
244-
return self._execute_as_job(code, invocation_context)
244+
# Fallback to existing GKE Job logic
245+
return self._execute_as_job(code, invocation_context)
245246

246247
def _create_job_manifest(
247248
self,

tests/unittests/code_executors/test_gke_code_executor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,4 +330,4 @@ def test_execute_code_forks_to_job(
330330
mock_k8s_clients["batch_v1"].create_namespaced_job.assert_called_once()
331331

332332
# Verify SandboxClient was NOT used
333-
mock_sandbox_client.assert_not_called()
333+
mock_sandbox_client.assert_not_called()

0 commit comments

Comments
 (0)