[PR #66] [MERGED] fix(template): create WORKDIR directories during template builds #151

Closed
opened 2026-10-29 14:20:17 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/kvcache-ai/AgentENV/pull/66
Author: @nblintao
Created: 7/29/2026
Status: ✅ Merged
Merged: 7/31/2026
Merged by: @huajq

Base: main ← Head: fix/workdir-step-mkdir


📝 Commits (4)

  • a18938f fix(template): create WORKDIR directories during template builds
  • 7032ec1 fix(template): resolve relative WORKDIR against the current workdir
  • 90b36e9 fix(template): normalize WORKDIR lexically and create it without a shell
  • babc0b3 fix(template): create WORKDIR via envd filesystem instead of exec'ing mkdir

📊 Changes

5 files changed (+273 additions, -7 deletions)

View changed files

📝 docs/src/concepts/templates.md (+1 -1)
📝 src/sandbox/backend.rs (+18 -0)
📝 src/sandbox/envd.rs (+16 -4)
📝 src/sandbox/process.rs (+21 -0)
📝 src/template/step_executor.rs (+217 -2)

📄 Description

Background

We work on miles, an RL training framework, and are integrating AgentENV as a sandbox backend for agentic RL environments through its E2B-compatible API. While running existing Dockerfile-defined task suites (Harbor tasks) against an AgentENV server via the stock e2b Python SDK, template builds succeeded but every sandbox failed on first command with:

e2b.exceptions.InvalidArgumentException: cwd '/app' does not exist

Problem

Docker's WORKDIR creates the directory when it does not exist (Dockerfile reference), but the template step executor only records the path as build-context metadata (src/template/step_executor.rs, TemplateBuildStepKind::Workdir). Any Dockerfile whose WORKDIR points at a directory not already present in the base image produces a template whose workdir is missing.

Both Dockerfile front-ends are affected:

  • the e2b SDK's Template().from_dockerfile(...), which maps WORKDIR to a workdir step — and additionally injects a default WORKDIR /home/user when the Dockerfile sets none, a directory that rarely exists in arbitrary OCI images;
  • aenv build, which maps the instruction the same way.

Minimal repro (e2b SDK against an AgentENV server):

t = Template().from_dockerfile("FROM ubuntu:24.04\nWORKDIR /app\n")
Template.build(t, "repro", ...)
sbx = Sandbox.create(template="repro", ...)
sbx.commands.run("pwd")   # InvalidArgumentException: cwd '/app' does not exist

Fix

Run mkdir -p inside the build sandbox when executing a workdir step, with the previous workdir as the cwd so relative WORKDIR paths resolve the way Docker resolves them. A failed mkdir fails the build, labelled with the WORKDIR step. Doc table updated accordingly.

Validation

  • cargo test --lib template — 34 passed (new: mkdir command shape, relative-path cwd resolution, failure labelling; workdir_step_updates_workdir moved to a recording sandbox since the step now executes a command).
  • E2E: rebuilt aenv-server with this fix and re-ran a previously failing Harbor task (FROM ubuntu:24.04 + WORKDIR /app, unmodified) through harbor run -e e2b against the patched server: the previously failing trial now passes end-to-end (verifier reward 1.0). Validated together with #67 on the same rebuilt server; each fix addresses an independent failure the task hits in sequence.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/kvcache-ai/AgentENV/pull/66 **Author:** [@nblintao](https://github.com/nblintao) **Created:** 7/29/2026 **Status:** ✅ Merged **Merged:** 7/31/2026 **Merged by:** [@huajq](https://github.com/huajq) **Base:** `main` ← **Head:** `fix/workdir-step-mkdir` --- ### 📝 Commits (4) - [`a18938f`](https://github.com/kvcache-ai/AgentENV/commit/a18938fbebc50c79d0ac0f9a11d669e759b7fea0) fix(template): create WORKDIR directories during template builds - [`7032ec1`](https://github.com/kvcache-ai/AgentENV/commit/7032ec17787f17ffde0ffa8dc61902a090d6fe0e) fix(template): resolve relative WORKDIR against the current workdir - [`90b36e9`](https://github.com/kvcache-ai/AgentENV/commit/90b36e9deb640be21d1b244fd81d6b6cfd7a9043) fix(template): normalize WORKDIR lexically and create it without a shell - [`babc0b3`](https://github.com/kvcache-ai/AgentENV/commit/babc0b3e71b9d063dd8d3a6c8c6af23c5150478c) fix(template): create WORKDIR via envd filesystem instead of exec'ing mkdir ### 📊 Changes **5 files changed** (+273 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `docs/src/concepts/templates.md` (+1 -1) 📝 `src/sandbox/backend.rs` (+18 -0) 📝 `src/sandbox/envd.rs` (+16 -4) 📝 `src/sandbox/process.rs` (+21 -0) 📝 `src/template/step_executor.rs` (+217 -2) </details> ### 📄 Description ## Background We work on [miles](https://github.com/radixark/miles), an RL training framework, and are integrating AgentENV as a sandbox backend for agentic RL environments through its E2B-compatible API. While running existing Dockerfile-defined task suites (Harbor tasks) against an AgentENV server via the stock e2b Python SDK, template builds succeeded but every sandbox failed on first command with: ``` e2b.exceptions.InvalidArgumentException: cwd '/app' does not exist ``` ## Problem Docker's `WORKDIR` creates the directory when it does not exist ([Dockerfile reference](https://docs.docker.com/reference/dockerfile/#workdir)), but the template step executor only records the path as build-context metadata (`src/template/step_executor.rs`, `TemplateBuildStepKind::Workdir`). Any Dockerfile whose `WORKDIR` points at a directory not already present in the base image produces a template whose workdir is missing. Both Dockerfile front-ends are affected: - the e2b SDK's `Template().from_dockerfile(...)`, which maps `WORKDIR` to a workdir step — and additionally injects a default `WORKDIR /home/user` when the Dockerfile sets none, a directory that rarely exists in arbitrary OCI images; - `aenv build`, which maps the instruction the same way. Minimal repro (e2b SDK against an AgentENV server): ```python t = Template().from_dockerfile("FROM ubuntu:24.04\nWORKDIR /app\n") Template.build(t, "repro", ...) sbx = Sandbox.create(template="repro", ...) sbx.commands.run("pwd") # InvalidArgumentException: cwd '/app' does not exist ``` ## Fix Run `mkdir -p` inside the build sandbox when executing a workdir step, with the previous workdir as the cwd so relative `WORKDIR` paths resolve the way Docker resolves them. A failed mkdir fails the build, labelled with the `WORKDIR` step. Doc table updated accordingly. ## Validation - `cargo test --lib template` — 34 passed (new: mkdir command shape, relative-path cwd resolution, failure labelling; `workdir_step_updates_workdir` moved to a recording sandbox since the step now executes a command). - E2E: rebuilt `aenv-server` with this fix and re-ran a previously failing Harbor task (`FROM ubuntu:24.04` + `WORKDIR /app`, unmodified) through `harbor run -e e2b` against the patched server: the previously failing trial now passes end-to-end (verifier reward 1.0). Validated together with #67 on the same rebuilt server; each fix addresses an independent failure the task hits in sequence. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 14:20:17 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
kvcache-ai/AgentENV#151
No description provided.