Skip to content

TaskSpec env is exported on the host but never passed into spec.container -- a container task silently runs without it #1059

Closed

Description

@scttfrdmn

Summary

TaskSpec.Env (pkg/taskproto/taskspec.go:30) is applied to the host wrapper shell but not to the container. So for any task with spec.container, the env map is accepted, validates, shows up in --dry-run, and has no effect on the command that actually runs.

Evidence

pkg/taskproto/wrapper.go (v0.128.2):

132	if len(spec.Env) > 0 {
134		for _, k := range sortedKeys(spec.Env) {
135			p("export %s=%s\n", k, shQuote(spec.Env[k]))
...
450	p("  sudo docker run --rm --user \"$(id -u):$(id -g)\" %s%s%s %s\n", gpuFlag, mounts.String(), shQuote(image), quoteArgv(spec.Command))

There's no -e/--env on line 450, so the exported variables stay in the host shell. And sudo drops the caller's environment by default anyway.

Measured on spawn 0.127.0, arm64 (mambaorg/micromamba image):

{"container": "docker.io/mambaorg/micromamba@sha256:26c186ed…",
 "command": ["bash","-c","echo \"in container: COOKBOOK_PROBE=${COOKBOOK_PROBE:-<unset>}\""],
 "env": {"COOKBOOK_PROBE": "reached-the-container"}, ...}
in container: COOKBOOK_PROBE=<unset>

Why it matters

It's a guardrail that parses but doesn't act. The case that hit us: we wanted env to make a containerised tool hermetic. fMRIPrep reads TemplateFlow settings from the environment, and an image whose ENTRYPOINT is the tool itself can't set variables in a bash -c prefix, because spawn doesn't override the entrypoint either. The spec would have looked configured and run without the setting.

Suggested fix

Pass each key as -e KEY on the docker run line. Keep the host export so -e KEY picks up the value without putting it on the command line:

for _, k := range sortedKeys(spec.Env) { envFlags.WriteString(" -e " + shQuote(k)) }
p("  sudo --preserve-env=%s docker run --rm --user ... %s%s%s%s %s\n", keysCSV, envFlags.String(), gpuFlag, mounts, image, argv)

(or -e KEY=VALUE directly). A test asserting that the generated container line carries every spec.Env key would keep it from regressing.

Activity

  1. scttfrdmn commented on Oct 19, 2026

    @scttfrdmn
    ContributorAuthor

    Re-found independently while writing the tasks guide (#598), as #1133 item 1. Confirmed on main by generating a wrapper: export K=… on the host, then sudo docker run with no -e (pkg/taskproto/wrapper.go:133-140, :487). The guide warns about it.

  2. added this to the v0.135.2 milestone on Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions