Skip to content

fix(python-sdk): reject absolute copy() sources on every platform - #2118

Open
DZH166 wants to merge 1 commit into
e2b-dev:mainfrom
DZH166:fix/reject-absolute-copy-sources
Open

DZH166 wants to merge 1 commit into
e2b-dev:mainfrom
DZH166:fix/reject-absolute-copy-sources

Conversation

@DZH166

@DZH166 DZH166 commented Nov 10, 2026 •

Copy link
Copy Markdown

Problem

validate_relative_path() decides whether a copy() source is absolute with the host's path flavour:

if os.path.isabs(src):
    raise TemplateException(...)

That misses the forms that can never resolve inside the template context directory:

  • on Windows, ntpath.isabs() requires a drive, so the drive-less rooted forms /absolute/path, /, /etc/passwd and \absolute\path all pass the guard (verified: os.path.isabs("/absolute/path") == False on Python 3.13/win32);
  • on POSIX, a drive-prefixed C:\Windows\System32 passes.

The invalid COPY instruction is recorded silently, so the documented TemplateException never fires for these inputs and the mistake only surfaces much later from calculate_files_hash() as an unrelated ValueError: No files found in /absolute/path.

before: Template(...).copy('/absolute/path', '/app/') accepted ->
        FROM e2bdev/base
        COPY /absolute/path /app/
after : Invalid source path "/absolute/path": absolute paths are not allowed. Use a relative path within the context directory.

Fix

Reject both flavours explicitly: any leading / or \ (rooted, no drive needed), any drive-relative form (C:foo), and any ntpath/posixpath absolute path - while keeping legitimate relative paths such as dir/file, ./file and .. rejected/accepted exactly as before.

Tests

tests/shared/template/utils/test_validate_relative_path.py (10 new cases, sync and async templates):

pytest tests/shared/template/utils/test_validate_relative_path.py -q    # before: 10 failed, 19 passed   after: 29 passed

Full offline suite: 855 passed, 33 skipped, 3 failed - the 3 failures are OSError: [WinError 1314] from os.symlink() in test setup and fail identically on the pristine tree.


Devin Review

validate_relative_path used os.path.isabs, which only follows the host path flavour: on Windows the drive-less rooted forms /abs, /etc/passwd and \\\\abs all pass, and on POSIX a drive-prefixed C: path passes. Reject both flavours explicitly.
@DZH166
DZH166 requested a review from mishushakov as a code owner November 10, 2026 18:51
@cla-bot

cla-bot Bot commented Nov 10, 2026

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement, and we don't have @DZH166 on file. You can sign our CLA at https://e2b.dev/docs/cla . Once you've signed, post a comment here that says '@cla-bot check'

@changeset-bot

changeset-bot Bot commented Nov 10, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 24d636a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 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-10T18:56:50.223801Z 24d636a PR opened
ℹ️ 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 found 2 potential issues.

1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

# path flavour: a rooted or drive-prefixed source never resolves inside the
# context directory, and letting it through only defers the failure to the
# build's file-hash step.
if _is_absolute_path(src):

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.

🟡 JavaScript copy paths remain host-dependent

On POSIX, Python copy() now rejects C:\Windows\file, but JavaScript copy() accepts it. JavaScript validateRelativePath still uses host-dependent path.isAbsolute, so equivalent SDK calls diverge.

Learn more

The SDKs share a template-copy contract. This change makes Python reject drive-prefixed sources on POSIX, but JavaScript validateRelativePath only calls the host-dependent path.isAbsolute. JavaScript copy passes its sources through that validator, so it still records a Windows source on POSIX.

Example: On Linux, Python copy('C:\\Windows\\file', '/app/') raises immediately. JavaScript copy('C:\\Windows\\file', '/app/') accepts the source and later fails when the build looks for files.

Recommended fix: Apply equivalent cross-flavour checks to JavaScript validateRelativePath and cover the same paths in its copy tests.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

# path flavour: a rooted or drive-prefixed source never resolves inside the
# context directory, and letting it through only defers the failure to the
# build's file-hash step.
if _is_absolute_path(src):

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.

🟡 Copy behavior change lacks changeset

Python copy() now rejects sources it previously recorded, changing its public behavior. No changeset accompanies the SDK change, leaving the release without this fix.

Learn more

The new validator affects public Python copy and copy_items calls. These calls now raise immediately on Windows-shaped sources, instead of recording an instruction. The repository's changeset rule applies to public SDK surface changes, and this PR adds no changeset.

Example: A Linux user passing C:\\Windows\\file gets a TemplateException at copy() rather than an error during build; the release notes would omit the changed behavior.

Recommended fix: Generate a patch changeset for @e2b/python-sdk describing the new cross-platform path validation.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@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 changed code. I checked parity (T-1, T-2), errors (T-59, T-62, T-63), client-side validation scope (T-52), and docstrings (T-69, T-71).

1 violation found:

  • T-1 (inline): the stricter absolute-path check only exists in the Python SDK. JS validateRelativePath (packages/js-sdk/src/template/utils.ts) still uses the host's path.isAbsolute, so the two SDKs now accept different copy() sources.

Everything else is compliant. The check fits T-52(b): it turns a late, unrelated ValueError: No files found into an actionable error at the copy() call. The error message is unchanged and tells the user what to do (T-62/T-63). The :raises docstring is still in reST style (T-71). Sync and async share e2b/template/utils.py, so T-2 parity holds.

Not counted, because the lines are unchanged: this argument validation runs before any build starts but raises TemplateException, not InvalidArgumentException (T-59). The new tests lock that in with pytest.raises(TemplateException, ...), so a later move to InvalidArgumentException would need to update them.

# path flavour: a rooted or drive-prefixed source never resolves inside the
# context directory, and letting it through only defers the failure to the
# build's file-hash step.
if _is_absolute_path(src):

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.

T-1: JS, sync Python, and async Python must behave the same, not just share names. After this change, Python rejects drive-less rooted and drive-prefixed sources on every host. JS validateRelativePath in packages/js-sdk/src/template/utils.ts still calls host-flavoured path.isAbsolute(src), which gives:

src path.posix.isAbsolute path.win32.isAbsolute
\a false true
\\srv\share false true
C:\Windows false true
C:foo false false

So Template().copy('C:\\Windows', '/app/') now throws in Python on Linux/macOS but still passes JS validation there. C:foo passes JS validation on every host. Please make the same change in the JS SDK in this PR, per the repo's AGENTS.md: "ensure equivalent changes are applied to both JS as well as sync and async Python implementations". For example:

function isAbsolutePath(src: string): boolean {
  return (
    path.posix.isAbsolute(src) ||
    path.win32.isAbsolute(src) ||
    /^[A-Za-z]:/.test(src)
  )
}

// in validateRelativePath
if (isAbsolutePath(src)) {

Add matching cases to the JS validateRelativePath tests too.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 24d636a8c6

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

# leaves these drive-less, so they need their own check.
or path.startswith("\\")
# Drive-prefixed path (`C:\foo`, `C:foo`).
or ntpath.splitdrive(path)[0] != ""

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Mirror the new COPY validation in the JavaScript SDK

For C:drive-relative on either host platform, Python now raises TemplateException, but JS copy() still accepts the source because packages/js-sdk/src/template/utils.ts:37 only uses path.isAbsolute. Windows absolute and UNC sources are likewise still accepted by JS on POSIX. Apply the equivalent guard and regression tests in JS; otherwise this SDK change violates the cross-language equivalence requirement in AGENTS.md.

AGENTS.md reference: AGENTS.md:L3-L3

Useful? React with 👍 / 👎.

# path flavour: a rooted or drive-prefixed source never resolves inside the
# context directory, and letting it through only defers the failure to the
# build's file-hash step.
if _is_absolute_path(src):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add a changeset for the public copy-validation change

For callers of public Template.copy() and copy_items(), this changes accepted inputs and makes previously deferred failures raise TemplateException immediately. However, the commit adds no .changeset/*.md entry for @e2b/python-sdk, leaving this user-visible change unrecorded in the package's release/changelog metadata. Add the changeset required by AGENTS.md for changes to the SDK's public surface.

AGENTS.md reference: AGENTS.md:L6-L6

Useful? React with 👍 / 👎.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant