fix(code_executors): harden ContainerCodeExecutor sandbox by default#6074
fix(code_executors): harden ContainerCodeExecutor sandbox by default#6074adilburaksen wants to merge 1 commit into
Conversation
|
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! |
|
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. |
ContainerCodeExecutor runs model-generated code, which may be influenced by untrusted input (e.g. prompt injection). Start the container with networking disabled, all Linux capabilities dropped, and no-new-privileges by default so executed code cannot reach the network (including the cloud metadata endpoint at 169.254.169.254), internal services, or exfiltration destinations, nor escalate privileges. Networking can be re-enabled via network_disabled=False when the executed code is trusted. Add unit tests covering the hardened defaults and the opt-out, and add docker to the test dependency group so the tests are importable in CI.
f40320e to
f7eaec2
Compare
|
@rohityan fixed and rebased onto latest main. Summary of this push: Root cause of the failing tests: the new test module imports Changes:
Testing plan / results — ran the new tests locally with The two tests assert that, by default, |
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.