Skip to content

Clean sandbox build caches#959

Open
ross0x01 wants to merge 2 commits into
mainfrom
codex/clean-sandbox-build-caches
Open

Clean sandbox build caches#959
ross0x01 wants to merge 2 commits into
mainfrom
codex/clean-sandbox-build-caches

Conversation

@ross0x01

@ross0x01 ross0x01 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • clean apt metadata in the same layer as the initial system upgrade
  • disable pip download caching, use and remove a temporary npm cache before agent-browser doctor, and delete Go module/build caches after installing the Go binaries
  • assert that targeted caches are absent before validating the existing runtime tools
  • add focused structural coverage for same-layer cleanup and the single-stage E2B Dockerfile contract

Why

The sandbox Dockerfile removed some cache paths only in its final layer. Docker preserves files added by earlier layers, and the final recursive ownership pass can copy up retained content under /home/user, so those late deletions do not reclaim the earlier layer bytes.

Measured result

Paired local arm64 builds used origin/main and this PR head, the same Kali base digest, and the same package-source window:

origin/main PR head
Docker-reported image size 4,338,949,710 bytes (4.04 GiB) 2,434,434,019 bytes (2.27 GiB)
Go build cache 766,050,606 bytes absent
Go module cache 1,101,026,306 bytes absent
npm cache 32,995,611 bytes absent

The image is 1,904,515,691 bytes (1.77 GiB, 43.9%) smaller. Docker history also shows the Go install layer decreasing from approximately 2.15 GB to 151 MB, the final cleanup/ownership layer from approximately 2.18 GB to 151 MB, and the agent-browser install layer from 108 MB to 74.8 MB.

Both builds used a measurement-only direct URL for the current httpx arm64 release asset because the unchanged latest-release API lookup was rate-limited. This temporary adjustment was identical in both build contexts and is not part of the branch.

Behavior and compatibility

  • keeps every runtime tool, programming language, build dependency, locale, document utility, man page, and nuclei template
  • keeps agent-browser 0.26.0 and its existing offline quick doctor check
  • keeps the Dockerfile single-stage for Template.fromDockerfile compatibility
  • does not change E2B template names, runtime paths, or sandbox behavior

Validation

  • paired local Docker builds for linux/arm64 from origin/main and the PR head
  • cleaned-image runtime agent-browser doctor --offline --quick (5 pass, 0 warn, 0 fail)
  • cleaned-image runtime presence checks for interactsh-client, katana, cvemap, Go, Python, Node, npm, and pip
  • cleaned-image Python imports for reportlab, python-docx, openpyxl, python-pptx, pandas, odfpy, and requests
  • cleaned-image absence checks for Go build/module caches, pip cache, npm cache, temporary npm cache, and apt metadata/archives
  • commit hooks: pnpm typecheck
  • commit hooks: pnpm test (297 suites, 2,928 tests)
  • corepack pnpm jest __tests__/dockerfile-cache-cleanup.test.ts --runInBand (6 tests)
  • corepack pnpm exec eslint __tests__/dockerfile-cache-cleanup.test.ts
  • corepack pnpm exec prettier --check __tests__/dockerfile-cache-cleanup.test.ts
  • E2B Template.fromDockerfile load through the repository's tsx execution path (succeeded with only the existing unsupported LABEL/SHELL notices)

Manual verification

  1. Build the E2B template from docker/Dockerfile and start a sandbox.
  2. Run agent-browser doctor --offline --quick and confirm it completes without warnings or failures.
  3. Confirm interactsh-client, katana, cvemap, go, python3, and node resolve in the sandbox.
  4. Confirm /home/user/go/.cache, /home/user/go/pkg/mod, /home/user/.cache/pip, /home/user/.npm, and /tmp/npm-cache are absent.

Summary by CodeRabbit

  • Bug Fixes
    • Reduced leftover package and build caches in the sandbox environment.
    • Tightened cleanup for system packages after installation.
    • Updated Python installs to avoid caching and improved post-install cache removal.
    • Improved Node.js and Go tool installation cleanup by removing temporary caches.
    • Added stronger pre-validation to confirm caches are absent before proceeding.
    • Preserved the sandbox’s single-stage container build configuration.

@vercel

vercel Bot commented Jul 24, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hackerai Ready Ready Preview, Comment Jul 24, 2026 1:48pm

Request Review

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The sandbox Dockerfile now clears APT, pip, npm, and Go caches during tool installation. Tests parse the Dockerfile and verify cleanup commands, cache absence, required binaries, single-stage construction, and Dockerfile template integration.

Changes

Docker cache cleanup

Layer / File(s) Summary
Package installation cache controls
docker/Dockerfile, __tests__/dockerfile-cache-cleanup.test.ts
APT installation removes package metadata and archives, while all pip installations use --no-cache-dir; tests enforce these conditions.
Browser and Go cache cleanup
docker/Dockerfile, __tests__/dockerfile-cache-cleanup.test.ts
The agent-browser installation removes its temporary npm cache, and Go tool installation removes Go caches; targeted tests verify both flows.
Build and runtime validation
docker/Dockerfile, __tests__/dockerfile-cache-cleanup.test.ts
Validation checks cache paths and required binaries, while tests verify the validation commands, single-stage Dockerfile structure, and template usage.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: tightening cache cleanup in the sandbox Dockerfile and related validation tests.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/clean-sandbox-build-caches

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
docker/Dockerfile (1)

23-24: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Use --no-install-recommends in this APT layer.

The kali-archive-keyring sudo installation in the same layer still omits this flag, allowing unnecessary recommended packages into the image. Add it while touching this layer.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docker/Dockerfile` around lines 23 - 24, Update the APT installation command
in the Dockerfile layer to pass --no-install-recommends when installing
kali-archive-keyring and sudo, while preserving the existing upgrade and cleanup
steps.

Source: Linters/SAST tools

__tests__/dockerfile-cache-cleanup.test.ts (1)

113-121: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Bind the template assertion to this Dockerfile.

Checking only for .fromDockerfile( does not prove that e2b/template.ts uses docker/Dockerfile; it could reference a different file. Assert the actual path or loaded Dockerfile content. Please verify the template implementation.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@__tests__/dockerfile-cache-cleanup.test.ts` around lines 113 - 121, Update
the test named “keeps the E2B Dockerfile build single-stage” to verify that
e2b/template.ts specifically references docker/Dockerfile, using the template’s
actual implementation and path representation. Keep the existing single-stage
Dockerfile assertion and retain the .fromDockerfile() check as appropriate.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@__tests__/dockerfile-cache-cleanup.test.ts`:
- Around line 59-69: Update the test around the pipRuns assertion to inspect
each individual pip3 install command rather than comparing aggregate counts. For
every entry in pipRuns, parse or isolate the install command and assert that it
contains --no-cache-dir, while preserving the existing check that at least one
pip command exists.
- Around line 72-91: Update the tests for the npm and Go installation flows to
assert complete ordering: verify each cleanup command occurs after its
corresponding install command and, for npm, before the agent-browser doctor
command. Use the existing npmRun, goRun, cleanupIndex, doctorIndex, and findRun
assertions, adding install-command positions without weakening the current
cache-content checks.

---

Nitpick comments:
In `@__tests__/dockerfile-cache-cleanup.test.ts`:
- Around line 113-121: Update the test named “keeps the E2B Dockerfile build
single-stage” to verify that e2b/template.ts specifically references
docker/Dockerfile, using the template’s actual implementation and path
representation. Keep the existing single-stage Dockerfile assertion and retain
the .fromDockerfile() check as appropriate.

In `@docker/Dockerfile`:
- Around line 23-24: Update the APT installation command in the Dockerfile layer
to pass --no-install-recommends when installing kali-archive-keyring and sudo,
while preserving the existing upgrade and cleanup steps.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f1a6a623-a385-434e-981a-b42abe767644

📥 Commits

Reviewing files that changed from the base of the PR and between 2fd0b8a and 836ea03.

📒 Files selected for processing (2)
  • __tests__/dockerfile-cache-cleanup.test.ts
  • docker/Dockerfile

Comment thread __tests__/dockerfile-cache-cleanup.test.ts
Comment thread __tests__/dockerfile-cache-cleanup.test.ts

Copy link
Copy Markdown
Contributor Author

Addressed the scope-compatible review feedback in f97a258: per-command pip cache assertions, complete npm/Go install-to-cleanup ordering, and an exact e2b/template.ts reference to docker/Dockerfile.

I kept the bootstrap apt-get install unchanged. Adding --no-install-recommends changes dependency selection rather than cache retention, so it is outside this cache-only PR and could alter the runtime package set. The main tool installation layer already uses --no-install-recommends.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant