Repository navigation
Read DOCKER_AGENT_ENV_-prefixed secret variables before the plain names #4702
Description
Overview
Let docker-agent read DOCKER_AGENT_ENV_<NAME> in preference to <NAME> for every secret it resolves (e.g. DOCKER_AGENT_ENV_ANTHROPIC_API_KEY before ANTHROPIC_API_KEY).
Motivation
docker-agent resolves op:// 1Password references, which is a nice way to avoid plain-text keys. But the variable names are shared with other tools: exporting ANTHROPIC_API_KEY="op://…" in the shell breaks Claude Code, Codex and provider SDKs, which do not resolve op://. Today the workarounds are the docker-agent env file (~/.config/cagent/.env) or a per-model token_key, which must be repeated in every model of every config and does not apply to --model provider/model.
Use cases
export DOCKER_AGENT_ENV_ANTHROPIC_API_KEY="op://Personal/Anthropic/api-key"
export ANTHROPIC_API_KEY=sk-ant-... # or unset; used by other tools
docker agent run agent.yaml # uses the op:// referenceAlso lets a user point docker-agent at a different key (separate billing/project) without touching other tools.
Proposed solution
A PrefixedProvider decorator in pkg/environment, wired through a single chain constructor as OnePassword(Prefixed(Multi(sources...))), so a prefixed value can itself be an op:// reference.
Decisions (revised after code review, see the comment below):
- Prefix
DOCKER_AGENT_ENV_.DOCKER_AGENT_is docker-agent's settings namespace; names already in it are never looked up as overrides. - Precedence:
DOCKER_AGENT_ENV_<NAME>wins across the whole chain,--env-from-fileincluded. - Empty values: an empty override is ignored and
<NAME>is used.
Doctor and follow-ups:
docker agent doctor(findSource) queries sources directly and would report the key as missing; teach it the prefix and show which name supplied the value.- The TUI transcriber reads
OPENAI_API_KEYwithos.Getenv(bypassing bothop://and the prefix); fixing it needs lazy resolution, so it is deferred to a separate PR.
Known limitation: in --sandbox, keys Docker Desktop proxies itself (OPENAI_API_KEY, ANTHROPIC_API_KEY, …) never go through our chain, so neither op:// nor the prefix applies to them there. Documented, not changed.
Alternatives
- Per-model
token_key: works, but verbose and not available for--modelshorthand. - Docker Agent env file: works, but a plain shell export of the same name still wins, which is the common setup for users of several AI tools.
Related issues
- docs(secrets): credential helper only supplies DOCKER_TOKEN #4701: docs fix for the credential helper scope and an
op://isolation tip. - Let credential_helper supply API keys and other secrets, not only DOCKER_TOKEN #4703: credential helper for all secrets.
- feat: read DOCKER_AGENT_ENV_-prefixed secret variables #4708: implementation.
Activity
[-]Read DOCKER_AGENT_-prefixed secret variables before the plain names[/-][+]Read DOCKER_AGENT_ENV_-prefixed secret variables before the plain names[/+]aheritier commentedon Oct 22, 2026
Revised after a code review of #4708:
DOCKER_AGENT_ENV_. With a bareDOCKER_AGENT_prefix, an MCP${REMOTE_AUTH_TOKEN}would have resolved to docker-agent's ownDOCKER_AGENT_REMOTE_AUTH_TOKEN(same forENCRYPT_KEY,DATA_DIR, …), leaking settings or secrets to tools.DOCKER_AGENT_ENV_is a sub-namespace no setting uses, and names already inDOCKER_AGENT_are never looked up as overrides.<NAME>instead of winning, so a blank line orexport X=cannot hide a valid key;doctorand the runtime now agree.--env-from-filejoins the same chain, so the override applies there too. Side effect:op://values in--env-from-fileare now resolved, as the docs already claimed.The description above is updated accordingly.
feat(environment): read DOCKER_AGENT_ENV_-prefixed secret variables
feat(doctor): report credentials found under DOCKER_AGENT_ENV_ names
docs(secrets): document DOCKER_AGENT_ENV_-prefixed variables
feat(environment): read DOCKER_AGENT_ENV_-prefixed secret variables
feat(doctor): report credentials found under DOCKER_AGENT_ENV_ names
docs(secrets): document DOCKER_AGENT_ENV_-prefixed variables