Description
When running Agent Zero as a Kubernetes Deployment (K3s with containerd runtime), the Context Engine plugin's _is_inside_container() function in execute.py returns False. This causes the setup to fall into the "Host (Docker mode)" branch, which then fails with:
Environment: Host (Docker mode)
Checking Docker...
✗ Docker is not available.
Install Docker Desktop: https://www.docker.com/products/docker-desktop/
The embedded mode (which would work fine without Docker) is never reached.
Environment
- Agent Zero:
agent0ai/agent-zero:v1.3
- Plugin version: commit
187b169
- Runtime: K3s v1.31 single-node cluster (RHEL 9, containerd runtime)
- Container runtime: containerd (not Docker)
- cgroup version: cgroupv2
Root Cause
_is_inside_container() checks three signals, all of which fail in a K3s/containerd environment:
/.dockerenv — Does not exist (containerd doesn't create it)
DOCKER_CONTAINER / container env vars — Not set (only KUBERNETES_SERVICE_HOST etc. are present)
/proc/1/cgroup — Contains only 0::/ (cgroupv2 format), so neither "docker" nor "kubepods" is found
Additionally, there's a Python bug in the cgroup check:
with open("/proc/1/cgroup", "r") as f:
return "docker" in f.read() or "kubepods" in f.read()
f.read() is called twice — the first call consumes the entire file, so the second f.read() always returns "". Even on cgroupv1 systems where the file contains "kubepods", the check would still fail.
Suggested Fix
def _is_inside_container() -> bool:
"""Detect if we're running inside a Docker/Kubernetes container."""
if os.path.exists("/.dockerenv"):
return True
if os.environ.get("DOCKER_CONTAINER") or os.environ.get("container"):
return True
# Kubernetes detection
if os.environ.get("KUBERNETES_SERVICE_HOST"):
return True
try:
with open("/proc/1/cgroup", "r") as f:
content = f.read()
return "docker" in content or "kubepods" in content
except (FileNotFoundError, PermissionError):
pass
return False
Key changes:
- Add
KUBERNETES_SERVICE_HOST check — This env var is always injected by Kubernetes into every pod
- Fix double
f.read() bug — Read file content once into a variable
Workaround
Setting the container environment variable in the Kubernetes Deployment spec works as a temporary workaround:
env:
- name: container
value: "kubernetes"
Description
When running Agent Zero as a Kubernetes Deployment (K3s with containerd runtime), the Context Engine plugin's
_is_inside_container()function inexecute.pyreturnsFalse. This causes the setup to fall into the "Host (Docker mode)" branch, which then fails with:The embedded mode (which would work fine without Docker) is never reached.
Environment
agent0ai/agent-zero:v1.3187b169Root Cause
_is_inside_container()checks three signals, all of which fail in a K3s/containerd environment:/.dockerenv— Does not exist (containerd doesn't create it)DOCKER_CONTAINER/containerenv vars — Not set (onlyKUBERNETES_SERVICE_HOSTetc. are present)/proc/1/cgroup— Contains only0::/(cgroupv2 format), so neither"docker"nor"kubepods"is foundAdditionally, there's a Python bug in the cgroup check:
f.read()is called twice — the first call consumes the entire file, so the secondf.read()always returns"". Even on cgroupv1 systems where the file contains "kubepods", the check would still fail.Suggested Fix
Key changes:
KUBERNETES_SERVICE_HOSTcheck — This env var is always injected by Kubernetes into every podf.read()bug — Read file content once into a variableWorkaround
Setting the
containerenvironment variable in the Kubernetes Deployment spec works as a temporary workaround: