Skip to content

fix(python-sdk): strip uppercase/mixed-case AS stage alias in from_dockerfile - #1788

Open
eeshsaxena wants to merge 1 commit into
e2b-dev:mainfrom
eeshsaxena:fix/dockerfile-uppercase-as-alias
Open

fix(python-sdk): strip uppercase/mixed-case AS stage alias in from_dockerfile#1788
eeshsaxena wants to merge 1 commit into
e2b-dev:mainfrom
eeshsaxena:fix/dockerfile-uppercase-as-alias

Conversation

@eeshsaxena

Copy link
Copy Markdown

What

parse_dockerfile (used by Template.from_dockerfile) strips a stage alias from the base image, but only when it is written as lowercase as:

if " as " in base_image.lower():
    base_image = base_image.split(" as ")[0].strip()

The guard lowercases the string, but the split runs on the original-case value with a lowercase delimiter. So the canonical, uppercase Docker form is not stripped:

FROM node:24 AS builder   -> base_image = "node:24 AS builder"   (broken image ref)
FROM node:24 As Build     -> base_image = "node:24 As Build"
FROM node:24 as builder   -> base_image = "node:24"              (only this worked)

AS is case-insensitive in Dockerfiles (and the docs use uppercase), so this is the common case.

Fix

Match AS case-insensitively:

base_image = re.split(r"\s+as\s+", base_image, maxsplit=1, flags=re.IGNORECASE)[0].strip()

Verified against the real parse_dockerfile: FROM node:24 AS builder, as builder, As Build, and FROM node:24 all resolve to node:24. Added sync + async regression tests.

How the code was written

Authored with the help of a coding agent; I verified the fix by running the actual parse_dockerfile and can explain the change.

…ckerfile

parse_dockerfile checked base_image.lower() for " as " but then split the
original-case string on the lowercase " as ", so the canonical uppercase form
FROM node:24 AS builder left the base image as "node:24 AS builder" (a broken
image reference); only a lowercase " as " was stripped. Match AS
case-insensitively. Adds sync and async regression tests.
@cla-bot

cla-bot Bot commented Aug 28, 2026

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement, and we don't have @eeshsaxena 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 Aug 28, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 70db30a

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

@eeshsaxena

Copy link
Copy Markdown
Author

Concrete impact: a single-stage Dockerfile like FROM node:24 AS builder (the canonical uppercase form the Docker docs use) currently yields the base image "node:24 AS builder", which is not a valid image reference, so from_dockerfile builds a broken template. Lowercase happened to work, which is why it slipped through.

@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 — no violations found (0).

Principles checked against the changed lines: parity across JS / sync Python / async Python (T-1, T-2), builder error types (T-42), Python option/result typing (T-16, T-17), docstrings (T-69, T-71). The fix is confined to parse_dockerfile's internal base-image normalization and changes no public surface, so most of the API-shape rules don't apply.

  • T-1 / T-2 parity: verified the JS parser is not affected by the same bug — packages/js-sdk/src/template/dockerfileParser.ts takes argumentsData[0].getValue() from the FROM instruction, so the stage alias is a separate argument and never lands in baseImage. No JS-side change is owed here. The sync and async Python test mirrors are both updated identically, as T-2 requires.
  • T-42 (builder failures raise BuildException, not bare ValueError) is violated by the surrounding raise ValueError(...) lines in this file, but those are pre-existing and untouched by this PR, so out of scope.

Two non-TASTE notes, take or leave: the new comments in the source and both tests narrate the previous bug ("Previously only a lowercase as was stripped") rather than describing the code — that history reads better in the PR description than in the file; and per AGENTS.md a user-visible python-sdk fix normally wants a changeset in .changeset/, which this PR doesn't add.

@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: 70db30a044

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +106 to +108
base_image = re.split(
r"\s+as\s+", base_image, maxsplit=1, flags=re.IGNORECASE
)[0].strip()

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 patch changeset for the Python SDK fix

This changes the user-visible behavior of Template.from_dockerfile, but the commit contains no .changeset entry for @e2b/python-sdk. In the checked release workflow, Python publication is gated through is_release_for_package.sh, which returns true only when a changeset names that package, so this fix will not bump or publish the Python SDK until it happens to be included in an unrelated release. Add a patch changeset for @e2b/python-sdk.

AGENTS.md reference: AGENTS.md:L7-L7

Useful? React with 👍 / 👎.

@eeshsaxena

Copy link
Copy Markdown
Author

@cla-bot check

@cla-bot cla-bot Bot added the cla-signed label Aug 31, 2026
@cla-bot

cla-bot Bot commented Aug 31, 2026

Copy link
Copy Markdown

The cla-bot has been summoned, and re-checked this pull request!

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