Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Fixes CMD parser in Python from_dockerfile method (#1040)

Mish Ushakov7b687bddbbb7
diff --git a/.changeset/fluffy-shrimps-play.md b/.changeset/fluffy-shrimps-play.md
new file mode 100644
index 000000000..e0c5d997d
--- /dev/null
+++ b/.changeset/fluffy-shrimps-play.md
@@ -0,0 +1,5 @@
+---
+'@e2b/python-sdk': patch
+---
+
+fixed cmd parser in from_dockerfile
diff --git a/packages/js-sdk/tests/template/methods/fromDockerfile.test.ts b/packages/js-sdk/tests/template/methods/fromDockerfile.test.ts
index abf0d090f..29fd68327 100644
--- a/packages/js-sdk/tests/template/methods/fromDockerfile.test.ts
+++ b/packages/js-sdk/tests/template/methods/fromDockerfile.test.ts
@@ -7,7 +7,8 @@ buildTemplateTest('fromDockerfile', async () => {
const dockerfile = `FROM node:24
WORKDIR /app
COPY package.json .
-RUN npm install`
+RUN npm install
+ENTRYPOINT ["sleep", "20"]`
const template = Template().fromDockerfile(dockerfile)
@@ -71,6 +72,11 @@ RUN npm install`
template.instructions[5].args[0],
'user'
)
+ assert.equal(
+ // @ts-expect-error - startCmd is not a property of TemplateBuilder
+ template.startCmd,
+ 'sleep 20'
+ )
})
buildTemplateTest('fromDockerfile with default user and workdir', () => {
diff --git a/packages/python-sdk/e2b/template/dockerfile_parser.py b/packages/python-sdk/e2b/template/dockerfile_parser.py
index d93fef30b..e04f9d5bb 100644
--- a/packages/python-sdk/e2b/template/dockerfile_parser.py
+++ b/packages/python-sdk/e2b/template/dockerfile_parser.py
@@ -1,3 +1,4 @@
+import json
import os
import re
import tempfile
@@ -257,6 +258,14 @@ def _handle_cmd_entrypoint_instruction(
return
command = value.strip()
+ # Try to parse as JSON (for array format like CMD ["sleep", "infinity"])
+ try:
+ parsed_command = json.loads(command)
+ if isinstance(parsed_command, list):
+ command = " ".join(str(item) for item in parsed_command)
+ except Exception:
+ pass
+
# Import wait_for_timeout locally to avoid circular dependency
def wait_for_timeout(timeout: int) -> str:
# convert to seconds, but ensure minimum of 1 second
diff --git a/packages/python-sdk/tests/async/template_async/methods/test_from_dockerfile.py b/packages/python-sdk/tests/async/template_async/methods/test_from_dockerfile.py
index d37e036cb..597704e92 100644
--- a/packages/python-sdk/tests/async/template_async/methods/test_from_dockerfile.py
+++ b/packages/python-sdk/tests/async/template_async/methods/test_from_dockerfile.py
@@ -9,7 +9,8 @@ async def test_from_dockerfile():
dockerfile = """FROM node:24
WORKDIR /app
COPY package.json .
-RUN npm install"""
+RUN npm install
+ENTRYPOINT ["sleep", "20"]"""
template = AsyncTemplate().from_dockerfile(dockerfile)
@@ -37,6 +38,9 @@ RUN npm install"""
assert instructions[5]["type"] == InstructionType.USER
assert instructions[5]["args"][0] == "user"
+ # Start command
+ assert template._template._start_cmd == "sleep 20"
+
@pytest.mark.skip_debug()
async def test_from_dockerfile_with_default_user_and_workdir():
diff --git a/packages/python-sdk/tests/sync/template_sync/methods/test_from_dockerfile.py b/packages/python-sdk/tests/sync/template_sync/methods/test_from_dockerfile.py
index 8e636b5fa..5cb68d302 100644
--- a/packages/python-sdk/tests/sync/template_sync/methods/test_from_dockerfile.py
+++ b/packages/python-sdk/tests/sync/template_sync/methods/test_from_dockerfile.py
@@ -9,7 +9,8 @@ def test_from_dockerfile():
dockerfile = """FROM node:24
WORKDIR /app
COPY package.json .
-RUN npm install"""
+RUN npm install
+ENTRYPOINT ["sleep", "20"]"""
template = Template().from_dockerfile(dockerfile)
@@ -37,6 +38,9 @@ RUN npm install"""
assert instructions[5]["type"] == InstructionType.USER
assert instructions[5]["args"][0] == "user"
+ # Start command
+ assert template._template._start_cmd == "sleep 20"
+
@pytest.mark.skip_debug()
def test_from_dockerfile_with_default_user_and_workdir():