Skip to content

fix(code_executors): harden ContainerCodeExecutor sandbox by default#6074

Open
adilburaksen wants to merge 3 commits into
google:mainfrom
adilburaksen:harden/container-code-executor-network
Open

fix(code_executors): harden ContainerCodeExecutor sandbox by default#6074
adilburaksen wants to merge 3 commits into
google:mainfrom
adilburaksen:harden/container-code-executor-network

Conversation

@adilburaksen

Copy link
Copy Markdown

Summary

ContainerCodeExecutor runs 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:

  • GkeCodeExecutor runs under gVisor with cap_drop: ["ALL"], non-root, read-only root filesystem, and a strict security context.
  • BuiltInCodeExecutor / VertexAiCodeExecutor / AgentEngineSandboxCodeExecutor run in managed server-side sandboxes.
  • UnsafeLocalCodeExecutor is explicitly documented as unsafe.

ContainerCodeExecutor was the only executor running code with full network access and no isolation flags or warning.

Change

  • Start the container with network_disabled=True by default. This is exposed as a configurable network_disabled field — set it to False to re-enable networking when the executed code is trusted.
  • Drop all Linux capabilities (cap_drop=["ALL"]) and forbid privilege escalation (security_opt=["no-new-privileges"]), matching GkeCodeExecutor.
  • Document the security posture in the class docstring and point users to the sandboxed executors for untrusted code.
  • Add unit tests covering the hardened defaults and the opt-in network path.

Compatibility

Code that legitimately needs network access can opt back in with ContainerCodeExecutor(..., network_disabled=False). Dropping capabilities and no-new-privileges do not affect normal Python code execution.

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.
@adk-bot

adk-bot commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Response from ADK Triaging Agent

Hello @adilburaksen, thank you for creating this PR to harden the ContainerCodeExecutor sandbox!

While checking this PR against our contribution guidelines, I noticed a few things that need to be addressed:

  1. Testing Plan: Please include a dedicated testing plan section in your PR description explaining how you tested these changes.
  2. Logs / Test Results: Please provide logs or test output (e.g., the output of the new pytest unit tests) showing that the test suite passes successfully.
  3. CI Header Check Failure: The header-check CI status check failed. Please ensure all new and modified files have the correct Apache 2.0 license headers. You can automatically verify and fix this by running pre-commit run --all-files locally before pushing.

These steps will help the maintainers review your contribution more quickly and efficiently. Thank you!

@rohityan rohityan self-assigned this Jun 11, 2026
@rohityan rohityan added the request clarification [Status] The maintainer need clarification or more information from the author label Jun 11, 2026
@rohityan

Copy link
Copy Markdown
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.

@rohityan rohityan added the tools [Component] This issue is related to tools label Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

request clarification [Status] The maintainer need clarification or more information from the author tools [Component] This issue is related to tools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants