#878

ECW template build: ENV values containing $VAR are written literally to /etc/environment, so ENV PATH=...:$PATH makes every later step fail

OpenRGB-loopopened 1mo ago

What happens

The E2B template-build translator turns an ENV step into echo 'KEY=VALUE' >> /etc/environment (translate.rs, ENV arm). Later RUN steps reach the build VM through ssh ... -l <user> -- host "bash -s" (ssh.rs), so they only see these values through sshd's pam_env, which does not expand $VAR.

The E2B SDK keeps $VAR references raw when it parses a Dockerfile, so the common line ENV PATH=/root/.local/bin:$PATH arrives unexpanded. After that step, PATH in every new SSH session is the literal string /root/.local/bin:$PATH, and the next step fails before the user command runs:

bash: line 1: bash: command not found   (exit 127)

The same happens with Template().set_envs({"PATH": "/opt/x/bin:$PATH"}). One such line makes every later build step fail.

Expected (E2B behaviour)

e2b-dev/infra evaluates ENV values in the build environment (commands/env.go, evaluateValue runs printf "%s" "<value>") and passes the expanded result to later steps, so $PATH resolves to the previous PATH.

Reproduction (outside a SPACE VM)

Disposable container with stock Debian 12 openssh-server (/etc/pam.d/sshd has session required pam_env.so, UsePAM yes; Ubuntu's sshd.pam has the same line). Append exactly what the translator emits, then run a step the way ssh.rs does:

echo 'PATH=/opt/tool/bin:$PATH' >> /etc/environment
printf "env bash -c 'ls /' </dev/null\n" | ssh -l root -- 127.0.0.1 "bash -s"
# bash: line 1: bash: command not found   (exit 127)

Appending the evaluated value instead (v=$(printf "%s" "/opt/tool/bin:$PATH"); echo "PATH=$v" >> /etc/environment) works, and ls runs normally.

Not verified: a real SPACE build VM (Ubuntu 26.04 guest, OpenSSH 10.x) or the full API → build-manager path. The translator and SSH runner code above is unchanged at current main (d1abc66f).

Severity (self-assessed): medium. No data loss or security impact, but a single common Dockerfile line breaks the whole template build with a misleading error. Workaround: write absolute values without $VAR.

Possible directions (happy to follow whichever you prefer)

  1. Evaluate the value on the build VM before appending, like e2b (printf %s "<escaped value>" as root, escaping $( and backticks the way e2b does).
  2. Carry build-time env as native recipe env for later steps and keep /etc/environment only for runtime persistence.

Would you accept a PR for (1), with translator unit tests for $VAR, ${VAR} and literal values?

Drafted and posted by an AI agent on behalf of the account owner; the agent ran the reproduction above in a disposable container.

Activity

1
NancyKwongPerplexity1mo ago

Thanks for opening this issue! A SPACE maintainer will take a look.

CONTRIBUTING.md explains how we review outside contributions.