Skip to content

Fix/e2b sdk 2.31 compat - #9

Open
benlavalley wants to merge 2 commits into
circlesac:mainfrom
benlavalley:fix/e2b-sdk-2.31-compat
Open

Fix/e2b sdk 2.31 compat#9
benlavalley wants to merge 2 commits into
circlesac:mainfrom
benlavalley:fix/e2b-sdk-2.31-compat

Conversation

@benlavalley

@benlavalley benlavalley commented Jun 30, 2026

Copy link
Copy Markdown

User description

  • Bump e2b to ^2.31.0 and refresh deps (zod, hono, chanfana, dockerode, nanoid, vitest, zod-to-openapi); set version 26.5.0 and typescript ^6
  • Added version definition to package.json - was needed trying to install locally (without it got error with cli/bin/install.js unable to download the release because version was undefined)
  • Proxy: strip transfer-encoding header and buffer request body via arrayBuffer to avoid streaming/double-encoding issues - required after test failure test/integration/e2b-smoke.spec.ts on line 168 (await sbA.files.write("/tmp/isolated.txt", "sandbox-a”);)
  • e2b was updated to validate API key formatting - you can either adhere to their new validation ('e2b_' followed by 40 hex characters) or set 'validateApiKey: false' on the client. You will see the commit history first applied the validateApiKey: false, then I followed it up with an update to the new key format. I decided that was the better-long-term solution should e2b ever deprecate their support for validateApiKey.
  • There were a number of typescript issues I didn't address that seemed to be pre-existing - let me know if you want them addressed in this PR.

Resolves issue #7 and #8


CodeAnt-AI Description

Use E2B-compatible API keys and keep proxied requests working

What Changed

  • The serve command now generates API keys in the new e2b_... format instead of the old sk-sandbox-... format.
  • Existing config, tests, and docs were updated to use the new key format so the CLI and examples match current E2B validation.
  • Proxied requests now drop the transfer-encoding header and send buffered request bodies, which avoids broken uploads and double-encoding issues with the sandbox backend.
  • The CLI package version and supported dependencies were refreshed to work with the newer E2B SDK.

Impact

✅ Fewer sandbox startup failures
✅ Working API key validation with E2B
✅ Fewer broken proxy uploads

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

Summary by CodeRabbit

  • New Features

    • Updated API key formatting across setup and examples to match the current key style.
  • Bug Fixes

    • Improved request forwarding behavior to avoid transfer-encoding conflicts in proxy requests.
    • Fixed body handling for forwarded non-GET/HEAD requests for more reliable proxying.
  • Documentation

    • Refreshed usage and configuration examples to show the latest API key format.
  • Chores

    • Bumped the CLI version and refreshed several package dependencies.

- bump e2b to ^2.31.0 and refresh deps (zod, hono, chanfana, dockerode, nanoid, vitest, zod-to-openapi); set version 26.5.0 and typescript ^6
- added version definition to package.json - was needed trying to install locally (without it got error with cli/bin/install.js unable to download the release because version was undefined)
- proxy: strip transfer-encoding header and buffer request body via arrayBuffer to avoid streaming/double-encoding issues - required after test failure test/integration/e2b-smoke.spec.ts on line 168 (await sbA.files.write("/tmp/isolated.txt", "sandbox-a”);)
- e2b-smoke: set validateApiKey: false for the integration client - required after e2b commit 4a4bb36839 (broke key validation) and 78c200a (supported validateApiKey: false to skip it)
- Generate API keys with `e2b_` prefix instead of `sk-sandbox-` in serve command
- Update tests, docs, and skill guide to the new key format
- Drop `validateApiKey: false` from the e2b smoke test now that keys pass SDK validation
@codeant-ai

codeant-ai Bot commented Jun 30, 2026

Copy link
Copy Markdown

CodeAnt AI is reviewing your PR.

@codeant-ai

codeant-ai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Renames the generated API key prefix from sk-sandbox- to e2b_ (with 20 random bytes instead of 24) across the CLI serve command, all documentation examples, and tests. Also fixes the proxy to remove the transfer-encoding header and buffer request bodies via arrayBuffer(). Bumps cli/package.json to version 26.5.0 with updated dependencies.

Changes

API Key Rename, Proxy Fix, and Dependency Bumps

Layer / File(s) Summary
API key generation and proxy body handling
cli/src/commands/serve.ts, cli/src/server/services/proxy.ts
Key prefix changed from sk-sandbox- to e2b_ with 20 random bytes; proxy additionally strips transfer-encoding header and buffers request body via arrayBuffer() instead of streaming.
Tests updated for e2b_ prefix
cli/test/global-setup.ts, cli/test/unit/commands/serve.spec.ts
Integration TEST_API_KEY and all unit test stubs/assertions updated to e2b_-prefixed key values.
Docs updated for e2b_ prefix
README.md, docs/container-runtimes.md, skills/guide/SKILL.md
All apiKey placeholder examples updated from sk-sandbox-... to e2b_..... format.
Dependency bumps
cli/package.json
Version bumped to 26.5.0; multiple dependencies and devDependencies upgraded.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hippity hop, a new key appears,
e2b_ whispers where sk-sandbox- once was,
The proxy now buffers with ArrayBuffer cheers,
No transfer-encoding confusion because—
The rabbit refactored without any tears! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: updating the codebase for E2B SDK 2.31 compatibility.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@codeant-ai codeant-ai Bot added the size:S This PR changes 10-29 lines, ignoring generated files label Jun 30, 2026
Comment on lines 135 to 138
body:
c.req.method !== "GET" && c.req.method !== "HEAD"
? c.req.raw.body
? await c.req.raw.arrayBuffer()
: undefined,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion: Buffering every non-GET/HEAD request body with arrayBuffer() forces the proxy to load the full payload into memory before forwarding, which breaks streaming request behavior and can cause high memory usage or OOMs on large uploads. Forward the original request stream instead of eagerly buffering the entire body. [performance]

Severity Level: Major ⚠️
❌ Large sandbox file uploads may exhaust proxy memory.
⚠️ Envd proxy cannot stream request bodies to sandboxes.
⚠️ All non-GET envd data-plane calls lose streaming.
Steps of Reproduction ✅
1. Start the envd proxy server via `cli/src/server/index.ts:1-18`, which calls
`createApp()` and then `Bun.serve({ fetch: envdProxy.fetch })`, wiring all incoming
data-plane HTTP requests through the Hono app.

2. In `cli/src/server/app.ts:8-33`, observe that the app-level middleware routes all
data-plane requests to `handleProxyRequest(c, backends, sandboxId)` based on either the
Host header pattern, the `E2b-Sandbox-Id` header, or the `X-Access-Token` header, so any
non-GET/HEAD envd HTTP request will pass through `handleProxyRequest`.

3. In `cli/src/server/services/proxy.ts:65-140`, see that `handleProxyRequest` forwards
the request with `fetch(targetUrl, { method: c.req.method, headers, body: c.req.method !==
"GET" && c.req.method !== "HEAD" ? await c.req.raw.arrayBuffer() : undefined, duplex:
"half" })`, meaning every POST/PUT/etc. request body is fully read into an ArrayBuffer
before being sent to the sandbox container, rather than streaming the original request
body.

4. Use the E2B SDK in `cli/test/integration/e2b-smoke.spec.ts:12-45` as a concrete caller
pattern (e.g., `await sandbox.files.write("/tmp/test.txt", "hello e2b")`) and extend it to
a large payload (e.g., `sandbox.files.write("/tmp/big.bin", hugeString)`): the SDK sends a
non-GET request through envd, which hits `handleProxyRequest`; for such large bodies, the
`arrayBuffer()` call forces the proxy process to hold the entire payload in memory at
once, breaking streaming semantics and potentially exhausting memory for very large
uploads.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** cli/src/server/services/proxy.ts
**Line:** 135:138
**Comment:**
	*Performance: Buffering every non-GET/HEAD request body with `arrayBuffer()` forces the proxy to load the full payload into memory before forwarding, which breaks streaming request behavior and can cause high memory usage or OOMs on large uploads. Forward the original request stream instead of eagerly buffering the entire body.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

@codeant-ai

codeant-ai Bot commented Jun 30, 2026

Copy link
Copy Markdown

CodeAnt AI finished reviewing your PR.

@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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cli/test/unit/commands/serve.spec.ts (1)

38-64: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Assert the full E2B key shape in these tests. The first assertion only checks the e2b_ prefix, and the fixtures here are shorter than the 40-hex key generated in cli/src/commands/serve.ts. Use a full-shape regex and full-length fixtures so the suite catches regressions in key generation.

🤖 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 `@cli/test/unit/commands/serve.spec.ts` around lines 38 - 64, The
`serve.spec.ts` assertions only validate the `e2b_` prefix, so update the tests
around `run()` to check the full E2B API key format instead of a partial prefix.
Use a full-length regex matching the key shape generated in
`cli/src/commands/serve.ts`, and replace the short `apiKey` fixtures in the
`readConfigMock` cases with full-length values so the `writeConfigMock` and
`process.env.API_KEYS` expectations cover the real key generation contract.
🤖 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 `@cli/src/server/services/proxy.ts`:
- Around line 131-138: The proxy request path in handleProxyRequest is fully
buffering non-GET/HEAD bodies via c.req.raw.arrayBuffer(), which can blow up
memory on uploads. Update the fetch call in proxy.ts to stream c.req.raw.body
directly when available, or add a strict request-size guard before any
buffering; keep the logic centered around handleProxyRequest and its
fetch(targetUrl, ...) body handling.

---

Outside diff comments:
In `@cli/test/unit/commands/serve.spec.ts`:
- Around line 38-64: The `serve.spec.ts` assertions only validate the `e2b_`
prefix, so update the tests around `run()` to check the full E2B API key format
instead of a partial prefix. Use a full-length regex matching the key shape
generated in `cli/src/commands/serve.ts`, and replace the short `apiKey`
fixtures in the `readConfigMock` cases with full-length values so the
`writeConfigMock` and `process.env.API_KEYS` expectations cover the real key
generation contract.
🪄 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

Run ID: 73d85780-8a06-4245-8d1d-2ff8fb6e6e75

📥 Commits

Reviewing files that changed from the base of the PR and between bc80891 and d1b60ac.

⛔ Files ignored due to path filters (1)
  • cli/bun.lock is excluded by !**/*.lock
📒 Files selected for processing (8)
  • README.md
  • cli/package.json
  • cli/src/commands/serve.ts
  • cli/src/server/services/proxy.ts
  • cli/test/global-setup.ts
  • cli/test/unit/commands/serve.spec.ts
  • docs/container-runtimes.md
  • skills/guide/SKILL.md

Comment on lines 131 to 138
try {
const response = await fetch(targetUrl, {
method: c.req.method,
headers,
body:
c.req.method !== "GET" && c.req.method !== "HEAD"
? c.req.raw.body
? await c.req.raw.arrayBuffer()
: undefined,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n## file map\n'
git ls-files 'cli/src/server/**' | sed -n '1,200p'

printf '\n## outline proxy.ts\n'
ast-grep outline cli/src/server/services/proxy.ts --view expanded || true

printf '\n## outline app.ts\n'
ast-grep outline cli/src/server/app.ts --view expanded || true

printf '\n## relevant search\n'
rg -n "arrayBuffer\(\)|handleProxyRequest|fetch\(targetUrl|raw\.body|ReadableStream|body:" cli/src/server -S

Repository: circlesac/sandbox

Length of output: 2720


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n## proxy.ts lines 1-220\n'
sed -n '1,220p' cli/src/server/services/proxy.ts | cat -n

printf '\n## app.ts lines 1-140\n'
sed -n '1,140p' cli/src/server/app.ts | cat -n

Repository: circlesac/sandbox

Length of output: 10838


Avoid buffering proxy request bodies.

app.ts routes envd file traffic through handleProxyRequest, and this path turns every non-GET/HEAD request into await c.req.raw.arrayBuffer(). That fully buffers uploads in memory; stream c.req.raw.body into fetch or enforce a strict size cap before buffering.

🤖 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 `@cli/src/server/services/proxy.ts` around lines 131 - 138, The proxy request
path in handleProxyRequest is fully buffering non-GET/HEAD bodies via
c.req.raw.arrayBuffer(), which can blow up memory on uploads. Update the fetch
call in proxy.ts to stream c.req.raw.body directly when available, or add a
strict request-size guard before any buffering; keep the logic centered around
handleProxyRequest and its fetch(targetUrl, ...) body handling.

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

Labels

size:S This PR changes 10-29 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants