Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
fix(cli): use absolute import in generated Python build scripts (#1505)
mattteufel-e2bd071bb78c833
diff --git a/.changeset/migrate-python-build-import.md b/.changeset/migrate-python-build-import.mdnew file mode 100644index 000000000..cddb32973--- /dev/null+++ b/.changeset/migrate-python-build-import.md@@ -0,0 +1,5 @@+---+"@e2b/cli": patch+---++Fix `e2b template migrate` generating Python build scripts that fail to run as instructed. The generated `build_dev.py` / `build_prod.py` used a package-relative import (`from .template import template`) while the command instructs single-file execution (`python build_dev.py`), causing `ImportError: attempted relative import with no known parent package`. The scripts now use a runnable absolute import (`from template import template`).diff --git a/packages/cli/src/templates/python-build-async.hbs b/packages/cli/src/templates/python-build-async.hbsindex 7dee8d823..95e885d73 100644--- a/packages/cli/src/templates/python-build-async.hbs+++ b/packages/cli/src/templates/python-build-async.hbs@@ -1,6 +1,6 @@import asynciofrom e2b import AsyncTemplate, default_build_logger-from .template import template+from template import templateasync def main():diff --git a/packages/cli/src/templates/python-build-sync.hbs b/packages/cli/src/templates/python-build-sync.hbsindex 3282d48bc..78f9c32c0 100644--- a/packages/cli/src/templates/python-build-sync.hbs+++ b/packages/cli/src/templates/python-build-sync.hbs@@ -1,5 +1,5 @@from e2b import Template, default_build_logger-from .template import template+from template import templateif __name__ == "__main__":diff --git a/packages/cli/tests/commands/template/fixtures/complex-python/expected/python-async/build_dev.py b/packages/cli/tests/commands/template/fixtures/complex-python/expected/python-async/build_dev.pyindex e9831b18b..25af75629 100644--- a/packages/cli/tests/commands/template/fixtures/complex-python/expected/python-async/build_dev.py+++ b/packages/cli/tests/commands/template/fixtures/complex-python/expected/python-async/build_dev.py@@ -1,6 +1,6 @@import asynciofrom e2b import AsyncTemplate, default_build_logger-from .template import template+from template import templateasync def main():diff --git a/packages/cli/tests/commands/template/fixtures/complex-python/expected/python-async/build_prod.py b/packages/cli/tests/commands/template/fixtures/complex-python/expected/python-async/build_prod.pyindex 18aa5b660..1c5f3151a 100644--- a/packages/cli/tests/commands/template/fixtures/complex-python/expected/python-async/build_prod.py+++ b/packages/cli/tests/commands/template/fixtures/complex-python/expected/python-async/build_prod.py@@ -1,6 +1,6 @@import asynciofrom e2b import AsyncTemplate, default_build_logger-from .template import template+from template import templateasync def main():diff --git a/packages/cli/tests/commands/template/fixtures/complex-python/expected/python-sync/build_dev.py b/packages/cli/tests/commands/template/fixtures/complex-python/expected/python-sync/build_dev.pyindex 8c884a5f6..e0b1466fe 100644--- a/packages/cli/tests/commands/template/fixtures/complex-python/expected/python-sync/build_dev.py+++ b/packages/cli/tests/commands/template/fixtures/complex-python/expected/python-sync/build_dev.py@@ -1,5 +1,5 @@from e2b import Template, default_build_logger-from .template import template+from template import templateif __name__ == "__main__":diff --git a/packages/cli/tests/commands/template/fixtures/complex-python/expected/python-sync/build_prod.py b/packages/cli/tests/commands/template/fixtures/complex-python/expected/python-sync/build_prod.pyindex 082f75c42..b3639034e 100644--- a/packages/cli/tests/commands/template/fixtures/complex-python/expected/python-sync/build_prod.py+++ b/packages/cli/tests/commands/template/fixtures/complex-python/expected/python-sync/build_prod.py@@ -1,5 +1,5 @@from e2b import Template, default_build_logger-from .template import template+from template import templateif __name__ == "__main__":diff --git a/packages/cli/tests/commands/template/fixtures/copy-variations/expected/python-async/build_dev.py b/packages/cli/tests/commands/template/fixtures/copy-variations/expected/python-async/build_dev.pyindex d998b5a94..1ad567da8 100644--- a/packages/cli/tests/commands/template/fixtures/copy-variations/expected/python-async/build_dev.py+++ b/packages/cli/tests/commands/template/fixtures/copy-variations/expected/python-async/build_dev.py@@ -1,6 +1,6 @@import asynciofrom e2b import AsyncTemplate, default_build_logger-from .template import template+from template import templateasync def main():diff --git a/packages/cli/tests/commands/template/fixtures/copy-variations/expected/python-async/build_prod.py b/packages/cli/tests/commands/template/fixtures/copy-variations/expected/python-async/build_prod.pyindex f18d3c9b5..f7047a289 100644--- a/packages/cli/tests/commands/template/fixtures/copy-variations/expected/python-async/build_prod.py+++ b/packages/cli/tests/commands/template/fixtures/copy-variations/expected/python-async/build_prod.py@@ -1,6 +1,6 @@import asynciofrom e2b import AsyncTemplate, default_build_logger-from .template import template+from template import templateasync def main():diff --git a/packages/cli/tests/commands/template/fixtures/copy-variations/expected/python-sync/build_dev.py b/packages/cli/tests/commands/template/fixtures/copy-variations/expected/python-sync/build_dev.pyindex 570303273..03a5874ed 100644--- a/packages/cli/tests/commands/template/fixtures/copy-variations/expected/python-sync/build_dev.py+++ b/packages/cli/tests/commands/template/fixtures/copy-variations/expected/python-sync/build_dev.py@@ -1,5 +1,5 @@from e2b import Template, default_build_logger-from .template import template+from template import templateif __name__ == "__main__":diff --git a/packages/cli/tests/commands/template/fixtures/copy-variations/expected/python-sync/build_prod.py b/packages/cli/tests/commands/template/fixtures/copy-variations/expected/python-sync/build_prod.pyindex c8e6ac40a..b01cadf83 100644--- a/packages/cli/tests/commands/template/fixtures/copy-variations/expected/python-sync/build_prod.py+++ b/packages/cli/tests/commands/template/fixtures/copy-variations/expected/python-sync/build_prod.py@@ -1,5 +1,5 @@from e2b import Template, default_build_logger-from .template import template+from template import templateif __name__ == "__main__":diff --git a/packages/cli/tests/commands/template/fixtures/custom-commands/expected/python-async/build_dev.py b/packages/cli/tests/commands/template/fixtures/custom-commands/expected/python-async/build_dev.pyindex 33c1e1d6b..c4084caac 100644--- a/packages/cli/tests/commands/template/fixtures/custom-commands/expected/python-async/build_dev.py+++ b/packages/cli/tests/commands/template/fixtures/custom-commands/expected/python-async/build_dev.py@@ -1,6 +1,6 @@import asynciofrom e2b import AsyncTemplate, default_build_logger-from .template import template+from template import templateasync def main():diff --git a/packages/cli/tests/commands/template/fixtures/custom-commands/expected/python-async/build_prod.py b/packages/cli/tests/commands/template/fixtures/custom-commands/expected/python-async/build_prod.pyindex 7f0db5b05..0bcb2980f 100644--- a/packages/cli/tests/commands/template/fixtures/custom-commands/expected/python-async/build_prod.py+++ b/packages/cli/tests/commands/template/fixtures/custom-commands/expected/python-async/build_prod.py@@ -1,6 +1,6 @@import asynciofrom e2b import AsyncTemplate, default_build_logger-from .template import template+from template import templateasync def main():diff --git a/packages/cli/tests/commands/template/fixtures/custom-commands/expected/python-sync/build_dev.py b/packages/cli/tests/commands/template/fixtures/custom-commands/expected/python-sync/build_dev.pyindex 3ceaf7f5d..680b692a3 100644--- a/packages/cli/tests/commands/template/fixtures/custom-commands/expected/python-sync/build_dev.py+++ b/packages/cli/tests/commands/template/fixtures/custom-commands/expected/python-sync/build_dev.py@@ -1,5 +1,5 @@from e2b import Template, default_build_logger-from .template import template+from template import templateif __name__ == "__main__":diff --git a/packages/cli/tests/commands/template/fixtures/custom-commands/expected/python-sync/build_prod.py b/packages/cli/tests/commands/template/fixtures/custom-commands/expected/python-sync/build_prod.pyindex b8131505b..e6c1ca76e 100644--- a/packages/cli/tests/commands/template/fixtures/custom-commands/expected/python-sync/build_prod.py+++ b/packages/cli/tests/commands/template/fixtures/custom-commands/expected/python-sync/build_prod.py@@ -1,5 +1,5 @@from e2b import Template, default_build_logger-from .template import template+from template import templateif __name__ == "__main__":diff --git a/packages/cli/tests/commands/template/fixtures/minimal-dockerfile/expected/python-async/build_dev.py b/packages/cli/tests/commands/template/fixtures/minimal-dockerfile/expected/python-async/build_dev.pyindex d63430b19..f9178ee20 100644--- a/packages/cli/tests/commands/template/fixtures/minimal-dockerfile/expected/python-async/build_dev.py+++ b/packages/cli/tests/commands/template/fixtures/minimal-dockerfile/expected/python-async/build_dev.py@@ -1,6 +1,6 @@import asynciofrom e2b import AsyncTemplate, default_build_logger-from .template import template+from template import templateasync def main():diff --git a/packages/cli/tests/commands/template/fixtures/minimal-dockerfile/expected/python-async/build_prod.py b/packages/cli/tests/commands/template/fixtures/minimal-dockerfile/expected/python-async/build_prod.pyindex 499c26251..08f0c7485 100644--- a/packages/cli/tests/commands/template/fixtures/minimal-dockerfile/expected/python-async/build_prod.py+++ b/packages/cli/tests/commands/template/fixtures/minimal-dockerfile/expected/python-async/build_prod.py@@ -1,6 +1,6 @@import asynciofrom e2b import AsyncTemplate, default_build_logger-from .template import template+from template import templateasync def main():diff --git a/packages/cli/tests/commands/template/fixtures/minimal-dockerfile/expected/python-sync/build_dev.py b/packages/cli/tests/commands/template/fixtures/minimal-dockerfile/expected/python-sync/build_dev.pyindex 9d7aa78cc..4df82d1f9 100644--- a/packages/cli/tests/commands/template/fixtures/minimal-dockerfile/expected/python-sync/build_dev.py+++ b/packages/cli/tests/commands/template/fixtures/minimal-dockerfile/expected/python-sync/build_dev.py@@ -1,5 +1,5 @@from e2b import Template, default_build_logger-from .template import template+from template import templateif __name__ == "__main__":diff --git a/packages/cli/tests/commands/template/fixtures/minimal-dockerfile/expected/python-sync/build_prod.py b/packages/cli/tests/commands/template/fixtures/minimal-dockerfile/expected/python-sync/build_prod.pyindex 62ccb29ee..30acefb3f 100644--- a/packages/cli/tests/commands/template/fixtures/minimal-dockerfile/expected/python-sync/build_prod.py+++ b/packages/cli/tests/commands/template/fixtures/minimal-dockerfile/expected/python-sync/build_prod.py@@ -1,5 +1,5 @@from e2b import Template, default_build_logger-from .template import template+from template import templateif __name__ == "__main__":diff --git a/packages/cli/tests/commands/template/fixtures/multi-stage/expected/python-async/build_dev.py b/packages/cli/tests/commands/template/fixtures/multi-stage/expected/python-async/build_dev.pyindex 4cf9bfa48..16456db43 100644--- a/packages/cli/tests/commands/template/fixtures/multi-stage/expected/python-async/build_dev.py+++ b/packages/cli/tests/commands/template/fixtures/multi-stage/expected/python-async/build_dev.py@@ -1,6 +1,6 @@import asynciofrom e2b import AsyncTemplate, default_build_logger-from .template import template+from template import templateasync def main():diff --git a/packages/cli/tests/commands/template/fixtures/multi-stage/expected/python-async/build_prod.py b/packages/cli/tests/commands/template/fixtures/multi-stage/expected/python-async/build_prod.pyindex 23d29ef82..3cecb8d71 100644--- a/packages/cli/tests/commands/template/fixtures/multi-stage/expected/python-async/build_prod.py+++ b/packages/cli/tests/commands/template/fixtures/multi-stage/expected/python-async/build_prod.py@@ -1,6 +1,6 @@import asynciofrom e2b import AsyncTemplate, default_build_logger-from .template import template+from template import templateasync def main():diff --git a/packages/cli/tests/commands/template/fixtures/multi-stage/expected/python-sync/build_dev.py b/packages/cli/tests/commands/template/fixtures/multi-stage/expected/python-sync/build_dev.pyindex ff50bda88..cc7e4e9b5 100644--- a/packages/cli/tests/commands/template/fixtures/multi-stage/expected/python-sync/build_dev.py+++ b/packages/cli/tests/commands/template/fixtures/multi-stage/expected/python-sync/build_dev.py@@ -1,5 +1,5 @@from e2b import Template, default_build_logger-from .template import template+from template import templateif __name__ == "__main__":diff --git a/packages/cli/tests/commands/template/fixtures/multi-stage/expected/python-sync/build_prod.py b/packages/cli/tests/commands/template/fixtures/multi-stage/expected/python-sync/build_prod.pyindex 0482afd92..c8aff7ed3 100644--- a/packages/cli/tests/commands/template/fixtures/multi-stage/expected/python-sync/build_prod.py+++ b/packages/cli/tests/commands/template/fixtures/multi-stage/expected/python-sync/build_prod.py@@ -1,5 +1,5 @@from e2b import Template, default_build_logger-from .template import template+from template import templateif __name__ == "__main__":diff --git a/packages/cli/tests/commands/template/fixtures/multiple-env/expected/python-async/build_dev.py b/packages/cli/tests/commands/template/fixtures/multiple-env/expected/python-async/build_dev.pyindex e412fea8c..03d821c99 100644--- a/packages/cli/tests/commands/template/fixtures/multiple-env/expected/python-async/build_dev.py+++ b/packages/cli/tests/commands/template/fixtures/multiple-env/expected/python-async/build_dev.py@@ -1,6 +1,6 @@import asynciofrom e2b import AsyncTemplate, default_build_logger-from .template import template+from template import templateasync def main():diff --git a/packages/cli/tests/commands/template/fixtures/multiple-env/expected/python-async/build_prod.py b/packages/cli/tests/commands/template/fixtures/multiple-env/expected/python-async/build_prod.pyindex 429b2bef0..00fbf6ae7 100644--- a/packages/cli/tests/commands/template/fixtures/multiple-env/expected/python-async/build_prod.py+++ b/packages/cli/tests/commands/template/fixtures/multiple-env/expected/python-async/build_prod.py@@ -1,6 +1,6 @@import asynciofrom e2b import AsyncTemplate, default_build_logger-from .template import template+from template import templateasync def main():diff --git a/packages/cli/tests/commands/template/fixtures/multiple-env/expected/python-sync/build_dev.py b/packages/cli/tests/commands/template/fixtures/multiple-env/expected/python-sync/build_dev.pyindex 109806c79..1cac5877c 100644--- a/packages/cli/tests/commands/template/fixtures/multiple-env/expected/python-sync/build_dev.py+++ b/packages/cli/tests/commands/template/fixtures/multiple-env/expected/python-sync/build_dev.py@@ -1,5 +1,5 @@from e2b import Template, default_build_logger-from .template import template+from template import templateif __name__ == "__main__":diff --git a/packages/cli/tests/commands/template/fixtures/multiple-env/expected/python-sync/build_prod.py b/packages/cli/tests/commands/template/fixtures/multiple-env/expected/python-sync/build_prod.pyindex c4920362e..e31216e81 100644--- a/packages/cli/tests/commands/template/fixtures/multiple-env/expected/python-sync/build_prod.py+++ b/packages/cli/tests/commands/template/fixtures/multiple-env/expected/python-sync/build_prod.py@@ -1,5 +1,5 @@from e2b import Template, default_build_logger-from .template import template+from template import templateif __name__ == "__main__":diff --git a/packages/cli/tests/commands/template/fixtures/start-cmd/expected/python-async/build_dev.py b/packages/cli/tests/commands/template/fixtures/start-cmd/expected/python-async/build_dev.pyindex 01db35dbf..4f1bb29fe 100644--- a/packages/cli/tests/commands/template/fixtures/start-cmd/expected/python-async/build_dev.py+++ b/packages/cli/tests/commands/template/fixtures/start-cmd/expected/python-async/build_dev.py@@ -1,6 +1,6 @@import asynciofrom e2b import AsyncTemplate, default_build_logger-from .template import template+from template import templateasync def main():diff --git a/packages/cli/tests/commands/template/fixtures/start-cmd/expected/python-async/build_prod.py b/packages/cli/tests/commands/template/fixtures/start-cmd/expected/python-async/build_prod.pyindex d80427426..6eec99586 100644--- a/packages/cli/tests/commands/template/fixtures/start-cmd/expected/python-async/build_prod.py+++ b/packages/cli/tests/commands/template/fixtures/start-cmd/expected/python-async/build_prod.py@@ -1,6 +1,6 @@import asynciofrom e2b import AsyncTemplate, default_build_logger-from .template import template+from template import templateasync def main():diff --git a/packages/cli/tests/commands/template/fixtures/start-cmd/expected/python-sync/build_dev.py b/packages/cli/tests/commands/template/fixtures/start-cmd/expected/python-sync/build_dev.pyindex bd7bf61ca..f0ae5cdb5 100644--- a/packages/cli/tests/commands/template/fixtures/start-cmd/expected/python-sync/build_dev.py+++ b/packages/cli/tests/commands/template/fixtures/start-cmd/expected/python-sync/build_dev.py@@ -1,5 +1,5 @@from e2b import Template, default_build_logger-from .template import template+from template import templateif __name__ == "__main__":diff --git a/packages/cli/tests/commands/template/fixtures/start-cmd/expected/python-sync/build_prod.py b/packages/cli/tests/commands/template/fixtures/start-cmd/expected/python-sync/build_prod.pyindex 24a98cce3..c3f33de04 100644--- a/packages/cli/tests/commands/template/fixtures/start-cmd/expected/python-sync/build_prod.py+++ b/packages/cli/tests/commands/template/fixtures/start-cmd/expected/python-sync/build_prod.py@@ -1,5 +1,5 @@from e2b import Template, default_build_logger-from .template import template+from template import templateif __name__ == "__main__":diff --git a/packages/cli/tests/commands/template/migrate.test.ts b/packages/cli/tests/commands/template/migrate.test.tsindex 9dd87840e..ee6cbb3e5 100644--- a/packages/cli/tests/commands/template/migrate.test.ts+++ b/packages/cli/tests/commands/template/migrate.test.ts@@ -125,6 +125,15 @@ describe('Template Migration', () => {'utf-8')expect(buildProdFile.trim()).toEqual(expectedBuildProd.trim())+ if (+ language === Language.PythonSync ||+ language === Language.PythonAsync+ ) {+ for (const content of [buildDevFile, buildProdFile]) {+ expect(content).toContain('from template import template')+ expect(content).not.toContain('from .template import template')+ }+ }// Check that old files are renamed to .old extensionsconst oldDockerfilePath = path.join(testDir, 'e2b.Dockerfile.old')