Skip to content

fix(sandbox): make DockerSandbox work on Colima and clean up job dirs - #20

Merged
pranath-reddy merged 2 commits into
ML4SCI:mainfrom
aatmaj28:fix/sandbox-job-dir
Oct 26, 2026
Merged

pranath-reddy merged 2 commits into
ML4SCI:mainfrom
aatmaj28:fix/sandbox-job-dir

Conversation

@aatmaj28

Copy link
Copy Markdown
Contributor

What was broken

DockerSandbox created its job dir with tempfile.mkdtemp(), which on macOS lands under /var/folders. Colima doesn't share that path with its VM, so the container saw an empty /work and every Docker run failed with can't open file '/work/prog.py'. The codegen agent then burned all three retries on what was really an infrastructure error. The offline demo uses LocalSandbox, so it never caught this.

Separately, neither sandbox ever deleted its job dir, so every attempt and every test run left a folder behind.

What this changes

  • Docker job dirs now go under ~/.cache/dlens/sandbox/, which Colima and Docker Desktop both share by default. DLENS_SANDBOX_DIR overrides it.
  • Each run's job dir is a TemporaryDirectory, removed when run() returns.

API change: the output file is deleted along with the job dir, so ExecResult.output_path is replaced by ExecResult.output, which holds the .npy file's bytes. validate_output() loads from those bytes, and its checks and messages are unchanged. Nothing else in the repo used output_path.

Testing

  • uv run pytest: 124 passed. The 3 new tests cover the job-dir location and the cleanup, and they fail on main.
  • I also ran a real Docker run on Colima (dlens-lenstronomy:latest, lenstronomy 1.9.2). A lenstronomy script rendered and passed validation on the first attempt, and no job dirs were left behind.

DockerSandbox bind-mounts its job dir into the container, but created it
with tempfile.mkdtemp(), which on macOS lands under /var/folders. Colima
does not share that path with its VM, so the container saw an empty /work
and every run failed with "can't open file '/work/prog.py'". The agent
then spent all of its retries on an infrastructure error.

Job dirs now go under ~/.cache/dlens/sandbox/, which Colima and Docker
Desktop both share by default. DLENS_SANDBOX_DIR overrides it.
Both sandboxes created a job dir with mkdtemp() and never removed it, so
every codegen attempt and every test run left a directory behind.

Job dirs are now TemporaryDirectory objects, removed when run() returns.
Since the output file goes with them, ExecResult now carries the .npy
bytes in `output`, replacing `output_path`. validate_output() loads from
those bytes. Its checks and messages are unchanged.
@pranath-reddy
pranath-reddy merged commit 63debad into ML4SCI:main Oct 26, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants