Skip to content

fix(python-sdk): percent-encode IDs in request paths - #2184

Open
mishushakov wants to merge 2 commits into
mainfrom
mishushakov/python-encode-path-ids
Open

mishushakov wants to merge 2 commits into
mainfrom
mishushakov/python-encode-path-ids

Conversation

@mishushakov

@mishushakov mishushakov commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

The generated Python API client writes a path parameter into the URL as it is given, so an ID with a separator names a different route:

Sandbox.kill("../templates/tpl123")
# sent: DELETE /templates/tpl123

An application that passes an ID from its own users to the Python SDK lets that user reach other routes with the application's API key. Template IDs and names were already encoded, and the JS SDK encodes every path parameter.

Change

Sandbox, snapshot, volume, secret and build IDs now go through encode_path_param in the sync and the async SDK. That includes Volume.read_file, which builds its URL by hand, and Sandbox.set_paused_retention. It percent-encodes the value into one path segment and refuses an empty value, ., .. and None with InvalidArgumentException, since encoding cannot keep those in place. Any other value that is not a string, such as a uuid.UUID, is sent as its text, as before.

The refusal also reaches template names and IDs, which already went through encode_path_param: Template.exists("") now raises instead of sending a request to another route.

Sandbox.kill("../templates/tpl123")
# sent: DELETE /sandboxes/..%2Ftemplates%2Ftpl123, which the API refuses as a sandbox ID

Sandbox.kill("")        # InvalidArgumentException, no request
Volume.connect("..")    # InvalidArgumentException, no request
Secret.destroy("a/b")   # sent: DELETE /secrets/a%2Fb

Volume("a/b", "name", token=token).read_file("f.txt")
# sent: GET /volumecontent/a%2Fb/file?path=f.txt, was /volumecontent/a/b/file

Review notes

  • Coverage. I checked all 44 generated endpoints that take a path parameter against their call sites, and every request URL the SDK builds by hand. After this change none passes a caller-supplied value unencoded.
  • From review. Volume.read_file was missed at first because it does not go through the generated client (found by Devin and Bugbot). The URL is now built before the stream, so an unusable ID on a streamed read is refused when the method is called. Methods that take a caller-supplied ID document the refusal with a :raises line.
  • Tests go through the public classes and read the request path off a local server (tests/recording_backend.py), for both SDK flavours. Each was seen failing without its fix.
  • JS. The JS SDK already encodes every path parameter, so the routing bug does not exist there. It does not refuse an empty ID, . or .. yet; that check for JS is part of feat(sdk): refuse arguments the server never sees as given #2183.
  • Debug mode. kill, set_timeout, set_paused_retention and get_metrics return before the ID is checked when debug is on, as Bugbot noted. No request is sent on that path, and validation in debug mode is tracked separately in SDK-403, so it is left as it is here.
  • Standalone. Based on main; it no longer depends on feat(sdk): refuse arguments the server never sees as given #2183. Both PRs add the same Python test helpers and the same refusal in encode_path_param, with identical content, so they merge in either order without conflicts.

Linear: SDK-456

🤖 Generated with Claude Code

@cla-bot cla-bot Bot added the cla-signed label Nov 27, 2026
@changeset-bot

changeset-bot Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2eddfff

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

This PR includes changesets to release 3 packages
Name Type
@e2b/python-sdk Patch
@e2b/acp-python Patch
@e2b/code-interpreter-python 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

@cursor

cursor Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

PR Summary

Medium Risk
Security-relevant request routing is corrected and invalid IDs now fail locally, but behavior changes for edge-case inputs and touches many API call sites.

Overview
The Python SDK put sandbox, volume, secret, and build IDs into URL paths without encoding, so values like ../templates/x could hit a different API route under the caller’s API key while the JS SDK already encoded them.

encode_path_param now percent-encodes every caller-supplied path segment (including hand-built volume file URLs and build IDs), refuses "", ., .., and None with InvalidArgumentException before any HTTP call, and tests against a recording backend assert the paths on the wire for sync and async.

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

@mishushakov
mishushakov added this pull request to stack #2186 November 27, 2026 02:12
@linear-code

linear-code Bot commented Nov 27, 2026

Copy link
Copy Markdown

SDK-456

@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Package Artifacts

Built from a38d0d4. Download artifacts from this workflow run.

JS SDK (e2b@2.67.1-mishushakov-python-encode-path-ids.0, with @e2b/dockerfile-utils@0.1.3-mishushakov-python-encode-path-ids.0):

npm install ./e2b-dockerfile-utils-0.1.3-mishushakov-python-encode-path-ids.0.tgz ./e2b-2.67.1-mishushakov-python-encode-path-ids.0.tgz

CLI (@e2b/cli@2.26.1-mishushakov-python-encode-path-ids.0):

npm install ./e2b-cli-2.26.1-mishushakov-python-encode-path-ids.0.tgz

Code Interpreter JS SDK (@e2b/code-interpreter@2.9.2-mishushakov-python-encode-path-ids.0):

npm install ./e2b-code-interpreter-2.9.2-mishushakov-python-encode-path-ids.0.tgz

Desktop JS SDK (@e2b/desktop@2.5.1-mishushakov-python-encode-path-ids.0):

npm install ./e2b-desktop-2.5.1-mishushakov-python-encode-path-ids.0.tgz

Python SDK (e2b==2.67.0+mishushakov.python.encode.path.ids, with e2b-dockerfile-utils==0.1.2+mishushakov.python.encode.path.ids):

pip install ./e2b_dockerfile_utils-0.1.2+mishushakov.python.encode.path.ids-py3-none-any.whl ./e2b-2.67.0+mishushakov.python.encode.path.ids-py3-none-any.whl

Code Interpreter Python SDK (e2b-code-interpreter==2.11.13+mishushakov.python.encode.path.ids):

pip install ./e2b_code_interpreter-2.11.13+mishushakov.python.encode.path.ids-py3-none-any.whl

Desktop Python SDK (e2b-desktop==2.7.2+mishushakov.python.encode.path.ids):

pip install ./e2b_desktop-2.7.2+mishushakov.python.encode.path.ids-py3-none-any.whl

@devin-ai-integration devin-ai-integration Bot 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.

TASTE.md review of the Python path-ID encoding change.

Checked: T-1 (cross-SDK parity), T-2 (sync/async mirrors), T-52 (client-side validation only to prevent footguns), T-59 (InvalidArgumentException for pre-flight argument checks), T-62 / T-69 (documented failure modes), T-63 (error messages use the user's argument names).

Violations: 2

  1. T-1, inline on both volume files: Volume.read_file (sync and async) still writes self._volume_id raw into a hand-built URL. Python still doesn't match JS for volume reads.
  2. T-62 / T-69 (document when an error is thrown; every public method documents its failure modes): Sandbox.kill, set_timeout, pause, get_info, connect, Secret.update / get_info / destroy, and Volume.get_info / connect / destroy now raise InvalidArgumentException for "", ".", ".." or a non-string ID. Their docstrings don't mention it. For example, Sandbox.kill still says only :return: True if the sandbox was killed, False if the sandbox was not found. Add a line such as :raises InvalidArgumentException: when sandbox_idis empty,.or... to each method, in both sync and async. Those docstrings aren't in the diff, so this one has no inline comment.

Compliant: the new check raises InvalidArgumentException (T-59), it only guards a footgun the backend can't see once the URL has collapsed (T-52a), its message names the Python argument (sandbox_id, secret, volume_id) (T-63), and every changed call site appears identically in both the sync and async files (T-2).

cursor[bot]

This comment was marked as resolved.

@mishushakov
mishushakov removed this pull request from stack #2186 November 30, 2026 17:19
The generated API client writes a path parameter into the URL as given,
so an ID with a separator named a different route:
Sandbox.kill("../templates/x") sent DELETE /templates/x. Template calls
already encoded their IDs; sandbox, snapshot, volume, secret and build
IDs now go through encode_path_param too, including the URL that
Volume.read_file builds by hand. encode_path_param also refuses an empty
value and dot segments, which escaping cannot keep in place.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mishushakov
mishushakov changed the base branch from mishushakov/e2b-sdk-zod-pydantic-types to main November 30, 2026 17:21
@mishushakov
mishushakov force-pushed the mishushakov/python-encode-path-ids branch from 30d69e8 to 14639b5 Compare November 30, 2026 17:21

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 14639b5. Configure here.

@mishushakov
mishushakov marked this pull request as ready for review November 30, 2026 17:29
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-30T17:32:13.402369Z 14639b5 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@devin-ai-integration devin-ai-integration Bot 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.

🔍 Devin Review: 3 flags

Not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

@claude claude 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.

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Comment thread .changeset/python-encode-path-ids.md Resolved
Comment thread packages/python-sdk/e2b/api/__init__.py Resolved
Comment thread packages/python-sdk/e2b/api/__init__.py Resolved
…mplate refusal

A uuid.UUID passed as an ID was written into the URL as its text before
the encoding was added; refuse only None, an empty value and dot
segments. Name template names and IDs in the changeset and docstrings,
since the refusal in encode_path_param covers them too.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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