Problem
ECW translates the E2B WORKDIR step into a root mkdir -p <arg> and keeps <arg> as the working directory for later steps (crates/libs/api/src/routes/e2b/template_build/translate.rs, WORKDIR arm). Upstream E2B's WORKDIR (packages/orchestrator/pkg/template/build/commands/workdir.go in e2b-dev/infra) does two more things:
- It
chowns the newly created directories to the current template user. - It resolves a relative argument against the previous workdir (or
/).
Two user-visible differences follow:
- Root-owned workdir. With
Template().fromTemplate('code-interpreter-v1').setWorkdir('/home/user/app').runCmd('touch x'), or.setUser('user').setWorkdir('/app').runCmd(...), the directory is owned by root. The next RUN, executed asuser, fails withPermission denied. The same template builds on E2B. - Relative workdir.
.setWorkdir('/srv').setWorkdir('data')creates and usesdatarelative to the SSH login user's home (/root/datafor root) instead of/srv/data.fromDockerfileforwards DockerfileWORKDIRvalues unchanged, soWORKDIR /srvfollowed byWORKDIR datahits this too. A laterCOPYwith a relative destination becomesdata/<dest>, which build-mgr rejects as a relative copy destination.
Reproduction
The payloads come from the real e2b@2.29.1 JS SDK (Template.toJSON). I ported the translator's RUN/WORKDIR/USER handling and the upstream workdir.go behaviour, then ran both step sequences in a disposable Debian container as root and user. ssh -l was emulated with runuser -l. This was not a SPACE build VM.
| Case | SPACE translation | E2B semantics |
|---|---|---|
code-interpreter-v1, WORKDIR /home/user/app, RUN touch x | dir owner root, Permission denied, exit 1 | dir owner user, exit 0 |
USER user, WORKDIR /app, RUN echo {} > package.json | Permission denied, exit 1 | exit 0 |
WORKDIR /srv, WORKDIR data, RUN pwd | /root/data | /srv/data |
I also added two translator unit tests to template_build/translate/tests.rs (same pattern as code_runtime_base_runs_implicit_steps_as_user_in_home, lazy pool, no database). Both fail on main at 57c7c0c4 with Rust 1.98.0; the other 45 template_build::translate tests pass:
---- workdir_created_for_non_root_user_is_owned_by_that_user ----
expected a root step that chowns the new workdir to user:user, got [
Run { command: "mkdir -p '/home/user/app'", user: Some("root") },
]
---- relative_workdir_resolves_against_previous_workdir ----
left: "cd 'data' && {\npwd\n}"
right: "cd '/srv/data' && {\npwd\n}"Possible approach
In the WORKDIR arm, resolve a relative argument against the current workdir (or /). Then emit a root step that creates only the missing suffix and chown -Rs the first new directory to the current user, as workdir.go does. Store the resolved absolute path as the workdir. The two tests above would cover both cases. I'm happy to open a PR if this scope works for you.
Severity
Medium (self-assessed). E2B-compatible templates that set a workdir for a non-root user fail to build. Relative workdirs put files in the wrong place without any error. Workarounds exist: use absolute paths and add your own chown RUN step.
This issue was drafted with the help of an AI agent. The reproduction above was run, and its limits are stated.
Activity
3Thanks, this is useful. We are looking into it and will handle the fix ourselves, so nothing more is needed from you for now.
Thanks, the scope looks good and a pull request is welcome. Please include a test that fails without the fix, and put "Fixes #622" in the pull request description so it goes straight to review. Agreeing on scope does not guarantee the pull request will be merged.
Thanks for opening this issue! A SPACE maintainer will take a look.
CONTRIBUTING.md explains how we review outside contributions.