fix(code_executors): harden ContainerCodeExecutor sandbox by default#6074
Open
adilburaksen wants to merge 3 commits into
Open
fix(code_executors): harden ContainerCodeExecutor sandbox by default#6074adilburaksen wants to merge 3 commits into
adilburaksen wants to merge 3 commits into
Conversation
ContainerCodeExecutor runs model-generated code, which can be influenced by untrusted input (e.g. via prompt injection). It previously started the container with default Docker networking and no capability restrictions, so the executed code could reach the cloud metadata endpoint (169.254.169.254) and exfiltrate the host service-account credentials, reach internal services, or escalate privileges. Start the container with networking disabled (configurable via a new `network_disabled` field, default True), drop all Linux capabilities, and forbid privilege escalation -- aligning with the isolation posture of GkeCodeExecutor and the managed executors. Add unit tests covering the hardened defaults and the opt-in network path.
Collaborator
|
Response from ADK Triaging Agent Hello @adilburaksen, thank you for creating this PR to harden the While checking this PR against our contribution guidelines, I noticed a few things that need to be addressed:
These steps will help the maintainers review your contribution more quickly and efficiently. Thank you! |
Collaborator
|
Hi @adilburaksen, Thank you for your contribution! We appreciate you taking the time to submit this pull request. Can you please fix the failing unit tests before we can proceed with the review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ContainerCodeExecutorruns model-generated code, which can be influenced by untrusted input (e.g. via prompt injection). It starts the container with default Docker networking and no capability restrictions, so the executed code can reach the cloud metadata endpoint (169.254.169.254) — which yields the host service-account token — reach internal services, or escalate privileges.This is inconsistent with the isolation posture of every other ADK code executor:
GkeCodeExecutorruns under gVisor withcap_drop: ["ALL"], non-root, read-only root filesystem, and a strict security context.BuiltInCodeExecutor/VertexAiCodeExecutor/AgentEngineSandboxCodeExecutorrun in managed server-side sandboxes.UnsafeLocalCodeExecutoris explicitly documented as unsafe.ContainerCodeExecutorwas the only executor running code with full network access and no isolation flags or warning.Change
network_disabled=Trueby default. This is exposed as a configurablenetwork_disabledfield — set it toFalseto re-enable networking when the executed code is trusted.cap_drop=["ALL"]) and forbid privilege escalation (security_opt=["no-new-privileges"]), matchingGkeCodeExecutor.Compatibility
Code that legitimately needs network access can opt back in with
ContainerCodeExecutor(..., network_disabled=False). Dropping capabilities andno-new-privilegesdo not affect normal Python code execution.