Skip to content

fix(sdk): consistent rate limit error for envd 429 responses#1387

Merged
mishushakov merged 3 commits into
mainfrom
mishushakov/consistent-rate-limit-error
Jun 5, 2026
Merged

fix(sdk): consistent rate limit error for envd 429 responses#1387
mishushakov merged 3 commits into
mainfrom
mishushakov/consistent-rate-limit-error

Conversation

@mishushakov

@mishushakov mishushakov commented Jun 5, 2026

Copy link
Copy Markdown
Member

Summary

The main API client already raised RateLimitError (JS) / RateLimitException (Python) for HTTP 429, but the lower-level envd HTTP and RPC layers fell through to a generic sandbox error, so the same rate-limit condition surfaced as a different type depending on which request path hit it. This maps envd 429 (and the equivalent gRPC ResourceExhausted code) to the dedicated rate-limit error consistently across the JS SDK and the Python sync/async SDKs. The JS RPC layer was also missing the ResourceExhausted mapping entirely, which is now added for parity with Python.

Also includes a small Python-SDK cleanup: ConnectionConfig set request_timeout via _get_request_timeout and then immediately overwrote it with an inline copy of the same logic — the duplicate block is removed (no behavior change).

Changes

  • js-sdk/src/envd/api.ts, python-sdk/e2b/envd/api.py — envd HTTP 429 → RateLimitError/RateLimitException
  • js-sdk/src/envd/rpc.ts — added gRPC Code.ResourceExhaustedRateLimitError
  • python-sdk/e2b/connection_config.py — removed redundant request_timeout reassignment
  • Added unit tests for both the envd HTTP and RPC error mappers in JS and Python
  • Changeset (e2b: patch)

Usage example

import { Sandbox, RateLimitError } from 'e2b'

try {
  await sandbox.files.write('/tmp/file.txt', 'data')
} catch (err) {
  if (err instanceof RateLimitError) {
    // now reliably caught regardless of which request path was rate limited
  }
}
from e2b import RateLimitException

try:
    sandbox.files.write("/tmp/file.txt", "data")
except RateLimitException:
    ...

🤖 Generated with Claude Code

The main API client already raised RateLimitError/RateLimitException for
HTTP 429, but the envd HTTP and RPC layers fell through to a generic
sandbox error. Map envd 429 and gRPC ResourceExhausted to the dedicated
rate limit error across the JS SDK and Python sync/async SDKs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@cursor

cursor Bot commented Jun 5, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Narrow error-type change for throttling responses plus tests; Python timeout config is a no-op deduplication.

Overview
Envd rate limits now raise the same dedicated errors as the main API client (RateLimitError / RateLimitException) instead of a generic sandbox error when sandbox HTTP returns 429 or gRPC returns ResourceExhausted. The JS envd RPC mapper gains the ResourceExhausted mapping for parity with Python.

Callers can instanceof RateLimitError (or catch RateLimitException) on envd-backed paths such as files/commands, not only on top-level API calls.

Also removes a duplicate request_timeout assignment in Python ConnectionConfig (behavior unchanged) and adds unit tests for the envd HTTP/RPC error mappers in both SDKs, plus a patch changeset.

Reviewed by Cursor Bugbot for commit 633cc8a. Bugbot is set up for automated code reviews on this repo. Configure here.

@changeset-bot

changeset-bot Bot commented Jun 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 633cc8a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
e2b Patch
@e2b/python-sdk Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Package Artifacts

Built from 7212ea5. Download artifacts from this workflow run.

JS SDK (e2b@2.27.2-mishushakov-consistent-rate-limit-error.0):

npm install ./e2b-2.27.2-mishushakov-consistent-rate-limit-error.0.tgz

CLI (@e2b/cli@2.10.4-mishushakov-consistent-rate-limit-error.0):

npm install ./e2b-cli-2.10.4-mishushakov-consistent-rate-limit-error.0.tgz

Python SDK (e2b==2.25.1+mishushakov-consistent-rate-limit-error):

pip install ./e2b-2.25.1+mishushakov.consistent.rate.limit.error-py3-none-any.whl

@mishushakov mishushakov enabled auto-merge (squash) June 5, 2026 14:09
The request_timeout was assigned via _get_request_timeout and then
immediately overwritten by an inline copy of the same logic. Keep only
the helper call; no behavior change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Comment thread .changeset/rate-limit-error-consistency.md
The Python package is published as @e2b/python-sdk and is not
linked/fixed with the JS "e2b" package, so the Python changes would
have been missed by the release workflow.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@matthewlouisbrockman matthewlouisbrockman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm... i think there's an edge case in js-sdk/envd/api.ts where we're checking against !res.error instead of res.error === undefined but can do that in future PR cause not related to the 429 fix

@mishushakov mishushakov merged commit 5b2bb94 into main Jun 5, 2026
28 of 37 checks passed
@mishushakov mishushakov deleted the mishushakov/consistent-rate-limit-error branch June 5, 2026 17:44
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.

2 participants