2025-11-14 16:48:29 -08:00
|
|
|
import traceback
|
2025-11-28 22:34:13 +01:00
|
|
|
from types import SimpleNamespace
|
2026-01-27 14:41:24 +01:00
|
|
|
from typing import List, Optional
|
2025-11-28 22:34:13 +01:00
|
|
|
from uuid import uuid4
|
2025-11-14 16:48:29 -08:00
|
|
|
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
import pytest
|
|
|
|
|
import linecache
|
|
|
|
|
|
Improve method naming and consistency (#934)
<!-- CURSOR_SUMMARY -->
> [!NOTE]
> Unifies Template APIs across JS/Python with PathLike support, new
copyItems, option/name tweaks, and simpler registry auth via
credentials; updates parser, exports, and tests.
>
> - **Template API (JS + Python)**
> - Add PathLike support for paths in `copy`, `remove`, `rename`,
`makeDir`, `makeSymlink`, `setWorkdir`, and `gitClone`.
> - Introduce `copyItems` and corresponding `CopyItem` typing; adjust
Dockerfile parser to use `copyItems` overload.
> - Simplify registry auth: `fromImage(baseImage, credentials)` accepts
`{username,password}`; remove `fromRegistry`; update
`fromAWSRegistry`/`fromGCPRegistry` to take credentials and set config
internally.
> - Rename options: `ignoreFilePaths` -> `fileIgnorePatterns`;
`fileContextPath` can be `PathLike`.
> - Ensure internal hashing/upload use stringified paths; minor
enum/type tweaks (e.g., `InstructionType` as string enum, `forceUpload?:
true`).
> - **Exports**
> - Export `CopyItem` from JS `index.ts` and Python `__init__.py`.
> - **Tests**
> - Update stacktrace and build tests to new method names/signatures
(e.g., registry via `fromImage` credentials, new `copyItems` tests,
optional `skipCache` param).
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
95391030550a340fe99ebaac4494867b3e3e9507. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-10-09 00:51:02 +02:00
|
|
|
from e2b import Template, CopyItem, wait_for_timeout
|
2026-01-27 14:41:24 +01:00
|
|
|
from e2b.template.types import TemplateBuildStatus
|
2025-11-28 22:34:13 +01:00
|
|
|
import e2b.template_sync.main as template_sync_main
|
|
|
|
|
import e2b.template_sync.build_api as build_api_mod
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
|
2026-02-05 13:54:54 +01:00
|
|
|
non_existent_path = "nonexistent/path"
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
|
2025-11-28 22:34:13 +01:00
|
|
|
# map template alias -> failed step index
|
|
|
|
|
failure_map: dict[str, Optional[int]] = {
|
|
|
|
|
"from_image": 0,
|
|
|
|
|
"from_template": 0,
|
|
|
|
|
"from_dockerfile": 0,
|
|
|
|
|
"from_image_registry": 0,
|
|
|
|
|
"from_aws_registry": 0,
|
|
|
|
|
"from_gcp_registry": 0,
|
|
|
|
|
"copy": None,
|
|
|
|
|
"copy_items": None,
|
|
|
|
|
"remove": 1,
|
|
|
|
|
"rename": 1,
|
|
|
|
|
"make_dir": 1,
|
|
|
|
|
"make_symlink": 1,
|
|
|
|
|
"run_cmd": 1,
|
|
|
|
|
"set_workdir": 1,
|
|
|
|
|
"set_user": 1,
|
|
|
|
|
"pip_install": 1,
|
|
|
|
|
"npm_install": 1,
|
|
|
|
|
"apt_install": 1,
|
|
|
|
|
"git_clone": 1,
|
|
|
|
|
"set_start_cmd": 1,
|
|
|
|
|
"add_mcp_server": None,
|
|
|
|
|
"beta_dev_container_prebuild": 1,
|
|
|
|
|
"beta_set_dev_container_start": 1,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
|
def mock_template_build(monkeypatch):
|
2026-01-27 14:41:24 +01:00
|
|
|
def mock_request_build(
|
|
|
|
|
client, name: str, tags: Optional[List[str]], cpu_count: int, memory_mb: int
|
|
|
|
|
):
|
|
|
|
|
return SimpleNamespace(template_id=name, build_id=str(uuid4()), tags=tags or [])
|
2025-11-28 22:34:13 +01:00
|
|
|
|
|
|
|
|
def mock_trigger_build(client, template_id: str, build_id: str, template):
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
def mock_get_build_status(
|
|
|
|
|
client, template_id: str, build_id: str, logs_offset: int
|
|
|
|
|
):
|
|
|
|
|
step = failure_map[template_id]
|
|
|
|
|
reason = SimpleNamespace(
|
|
|
|
|
message="Mocked API build error",
|
|
|
|
|
log_entries=[],
|
|
|
|
|
step=str(step) if step is not None else None,
|
|
|
|
|
)
|
|
|
|
|
return SimpleNamespace(
|
|
|
|
|
status=TemplateBuildStatus.ERROR,
|
|
|
|
|
log_entries=[],
|
|
|
|
|
reason=reason,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
monkeypatch.setattr(template_sync_main, "request_build", mock_request_build)
|
|
|
|
|
monkeypatch.setattr(template_sync_main, "trigger_build", mock_trigger_build)
|
|
|
|
|
monkeypatch.setattr(build_api_mod, "get_build_status", mock_get_build_status)
|
|
|
|
|
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
|
|
|
|
|
def _expect_to_throw_and_check_trace(func, expected_method: str):
|
|
|
|
|
try:
|
|
|
|
|
func()
|
|
|
|
|
assert False, "Expected Template.build to raise an exception"
|
|
|
|
|
except Exception as e: # noqa: BLE001 - we want to assert on the traceback regardless of type
|
|
|
|
|
tb = e.__traceback__
|
|
|
|
|
saw_this_file = False
|
|
|
|
|
saw_expected_method = False
|
|
|
|
|
while tb is not None:
|
|
|
|
|
traceback_file = tb.tb_frame.f_code.co_filename
|
|
|
|
|
if traceback_file == __file__:
|
|
|
|
|
saw_this_file = True
|
|
|
|
|
caller_line = linecache.getline(traceback_file, tb.tb_lineno)
|
|
|
|
|
if caller_line and f".{expected_method}(" in caller_line:
|
|
|
|
|
saw_expected_method = True
|
|
|
|
|
break
|
|
|
|
|
tb = tb.tb_next
|
2025-11-14 16:48:29 -08:00
|
|
|
assert saw_this_file, traceback.format_exc()
|
|
|
|
|
assert saw_expected_method, traceback.format_exc()
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skip_debug()
|
2025-10-01 14:37:58 +02:00
|
|
|
def test_traces_on_from_image(build):
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
template = Template()
|
2025-11-06 15:50:02 +01:00
|
|
|
template = template.from_image("e2b.dev/this-image-does-not-exist")
|
|
|
|
|
_expect_to_throw_and_check_trace(
|
2026-01-27 14:41:24 +01:00
|
|
|
lambda: build(template, name="from_image", skip_cache=True), "from_image"
|
2025-11-06 15:50:02 +01:00
|
|
|
)
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
|
|
|
|
|
|
2025-10-15 18:31:50 +02:00
|
|
|
@pytest.mark.skip_debug()
|
|
|
|
|
def test_traces_on_from_template(build):
|
|
|
|
|
template = Template().from_template("this-template-does-not-exist")
|
2025-11-06 15:50:02 +01:00
|
|
|
_expect_to_throw_and_check_trace(
|
2026-01-27 14:41:24 +01:00
|
|
|
lambda: build(template, name="from_template", skip_cache=True), "from_template"
|
2025-11-06 15:50:02 +01:00
|
|
|
)
|
2025-10-15 18:31:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skip_debug()
|
|
|
|
|
def test_traces_on_from_dockerfile(build):
|
|
|
|
|
template = Template()
|
|
|
|
|
template = template.from_dockerfile("FROM ubuntu:22.04\nRUN nonexistent")
|
2025-11-06 15:50:02 +01:00
|
|
|
_expect_to_throw_and_check_trace(
|
2026-01-27 14:41:24 +01:00
|
|
|
lambda: build(template, name="from_dockerfile", skip_cache=True),
|
2025-11-28 22:34:13 +01:00
|
|
|
"from_dockerfile",
|
2025-11-06 15:50:02 +01:00
|
|
|
)
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skip_debug()
|
Improve method naming and consistency (#934)
<!-- CURSOR_SUMMARY -->
> [!NOTE]
> Unifies Template APIs across JS/Python with PathLike support, new
copyItems, option/name tweaks, and simpler registry auth via
credentials; updates parser, exports, and tests.
>
> - **Template API (JS + Python)**
> - Add PathLike support for paths in `copy`, `remove`, `rename`,
`makeDir`, `makeSymlink`, `setWorkdir`, and `gitClone`.
> - Introduce `copyItems` and corresponding `CopyItem` typing; adjust
Dockerfile parser to use `copyItems` overload.
> - Simplify registry auth: `fromImage(baseImage, credentials)` accepts
`{username,password}`; remove `fromRegistry`; update
`fromAWSRegistry`/`fromGCPRegistry` to take credentials and set config
internally.
> - Rename options: `ignoreFilePaths` -> `fileIgnorePatterns`;
`fileContextPath` can be `PathLike`.
> - Ensure internal hashing/upload use stringified paths; minor
enum/type tweaks (e.g., `InstructionType` as string enum, `forceUpload?:
true`).
> - **Exports**
> - Export `CopyItem` from JS `index.ts` and Python `__init__.py`.
> - **Tests**
> - Update stacktrace and build tests to new method names/signatures
(e.g., registry via `fromImage` credentials, new `copyItems` tests,
optional `skipCache` param).
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
95391030550a340fe99ebaac4494867b3e3e9507. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-10-09 00:51:02 +02:00
|
|
|
def test_traces_on_from_image_registry(build):
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
template = Template()
|
2025-11-06 15:50:02 +01:00
|
|
|
template = template.from_image(
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
"registry.example.com/nonexistent:latest",
|
|
|
|
|
username="test",
|
|
|
|
|
password="test",
|
|
|
|
|
)
|
2025-11-06 15:50:02 +01:00
|
|
|
_expect_to_throw_and_check_trace(
|
2026-01-27 14:41:24 +01:00
|
|
|
lambda: build(template, name="from_image_registry", skip_cache=True),
|
2025-11-28 22:34:13 +01:00
|
|
|
"from_image",
|
2025-11-06 15:50:02 +01:00
|
|
|
)
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skip_debug()
|
2025-10-01 14:37:58 +02:00
|
|
|
def test_traces_on_from_aws_registry(build):
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
template = Template()
|
2025-11-06 15:50:02 +01:00
|
|
|
template = template.from_aws_registry(
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
"123456789.dkr.ecr.us-east-1.amazonaws.com/nonexistent:latest",
|
|
|
|
|
access_key_id="test",
|
|
|
|
|
secret_access_key="test",
|
|
|
|
|
region="us-east-1",
|
|
|
|
|
)
|
2025-11-06 15:50:02 +01:00
|
|
|
_expect_to_throw_and_check_trace(
|
2026-01-27 14:41:24 +01:00
|
|
|
lambda: build(template, name="from_aws_registry"), "from_aws_registry"
|
2025-11-06 15:50:02 +01:00
|
|
|
)
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skip_debug()
|
2025-10-01 14:37:58 +02:00
|
|
|
def test_traces_on_from_gcp_registry(build):
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
template = Template()
|
2025-11-06 15:50:02 +01:00
|
|
|
template = template.from_gcp_registry(
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
"gcr.io/nonexistent-project/nonexistent:latest",
|
|
|
|
|
service_account_json={
|
|
|
|
|
"type": "service_account",
|
|
|
|
|
},
|
|
|
|
|
)
|
2025-11-06 15:50:02 +01:00
|
|
|
_expect_to_throw_and_check_trace(
|
2026-01-27 14:41:24 +01:00
|
|
|
lambda: build(template, name="from_gcp_registry"), "from_gcp_registry"
|
2025-11-06 15:50:02 +01:00
|
|
|
)
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skip_debug()
|
2025-10-01 14:37:58 +02:00
|
|
|
def test_traces_on_copy(build):
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
template = Template()
|
|
|
|
|
template = template.from_base_image()
|
2025-09-26 14:01:41 +02:00
|
|
|
template = template.skip_cache().copy(non_existent_path, non_existent_path)
|
2026-01-27 14:41:24 +01:00
|
|
|
_expect_to_throw_and_check_trace(lambda: build(template, name="copy"), "copy")
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
|
|
|
|
|
|
Improve method naming and consistency (#934)
<!-- CURSOR_SUMMARY -->
> [!NOTE]
> Unifies Template APIs across JS/Python with PathLike support, new
copyItems, option/name tweaks, and simpler registry auth via
credentials; updates parser, exports, and tests.
>
> - **Template API (JS + Python)**
> - Add PathLike support for paths in `copy`, `remove`, `rename`,
`makeDir`, `makeSymlink`, `setWorkdir`, and `gitClone`.
> - Introduce `copyItems` and corresponding `CopyItem` typing; adjust
Dockerfile parser to use `copyItems` overload.
> - Simplify registry auth: `fromImage(baseImage, credentials)` accepts
`{username,password}`; remove `fromRegistry`; update
`fromAWSRegistry`/`fromGCPRegistry` to take credentials and set config
internally.
> - Rename options: `ignoreFilePaths` -> `fileIgnorePatterns`;
`fileContextPath` can be `PathLike`.
> - Ensure internal hashing/upload use stringified paths; minor
enum/type tweaks (e.g., `InstructionType` as string enum, `forceUpload?:
true`).
> - **Exports**
> - Export `CopyItem` from JS `index.ts` and Python `__init__.py`.
> - **Tests**
> - Update stacktrace and build tests to new method names/signatures
(e.g., registry via `fromImage` credentials, new `copyItems` tests,
optional `skipCache` param).
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
95391030550a340fe99ebaac4494867b3e3e9507. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-10-09 00:51:02 +02:00
|
|
|
@pytest.mark.skip_debug()
|
|
|
|
|
def test_traces_on_copyItems(build):
|
|
|
|
|
template = Template()
|
|
|
|
|
template = template.from_base_image()
|
|
|
|
|
template = template.skip_cache().copy_items(
|
|
|
|
|
[CopyItem(src=non_existent_path, dest=non_existent_path)]
|
|
|
|
|
)
|
2025-11-28 22:34:13 +01:00
|
|
|
_expect_to_throw_and_check_trace(
|
2026-01-27 14:41:24 +01:00
|
|
|
lambda: build(template, name="copy_items"), "copy_items"
|
2025-11-28 22:34:13 +01:00
|
|
|
)
|
Improve method naming and consistency (#934)
<!-- CURSOR_SUMMARY -->
> [!NOTE]
> Unifies Template APIs across JS/Python with PathLike support, new
copyItems, option/name tweaks, and simpler registry auth via
credentials; updates parser, exports, and tests.
>
> - **Template API (JS + Python)**
> - Add PathLike support for paths in `copy`, `remove`, `rename`,
`makeDir`, `makeSymlink`, `setWorkdir`, and `gitClone`.
> - Introduce `copyItems` and corresponding `CopyItem` typing; adjust
Dockerfile parser to use `copyItems` overload.
> - Simplify registry auth: `fromImage(baseImage, credentials)` accepts
`{username,password}`; remove `fromRegistry`; update
`fromAWSRegistry`/`fromGCPRegistry` to take credentials and set config
internally.
> - Rename options: `ignoreFilePaths` -> `fileIgnorePatterns`;
`fileContextPath` can be `PathLike`.
> - Ensure internal hashing/upload use stringified paths; minor
enum/type tweaks (e.g., `InstructionType` as string enum, `forceUpload?:
true`).
> - **Exports**
> - Export `CopyItem` from JS `index.ts` and Python `__init__.py`.
> - **Tests**
> - Update stacktrace and build tests to new method names/signatures
(e.g., registry via `fromImage` credentials, new `copyItems` tests,
optional `skipCache` param).
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
95391030550a340fe99ebaac4494867b3e3e9507. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-10-09 00:51:02 +02:00
|
|
|
|
|
|
|
|
|
2026-02-05 13:54:54 +01:00
|
|
|
@pytest.mark.skip_debug()
|
|
|
|
|
def test_traces_on_copy_absolute_path():
|
|
|
|
|
_expect_to_throw_and_check_trace(
|
|
|
|
|
lambda: Template().from_base_image().copy("/absolute/path", "/absolute/path"),
|
|
|
|
|
"copy",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skip_debug()
|
|
|
|
|
def test_traces_on_copyItems_absolute_path():
|
|
|
|
|
_expect_to_throw_and_check_trace(
|
2026-03-04 13:23:08 -08:00
|
|
|
lambda: (
|
|
|
|
|
Template()
|
|
|
|
|
.from_base_image()
|
|
|
|
|
.copy_items([CopyItem(src="/absolute/path", dest="/absolute/path")])
|
|
|
|
|
),
|
2026-02-05 13:54:54 +01:00
|
|
|
"copy_items",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
@pytest.mark.skip_debug()
|
2025-10-01 14:37:58 +02:00
|
|
|
def test_traces_on_remove(build):
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
template = Template()
|
|
|
|
|
template = template.from_base_image()
|
2025-09-26 14:01:41 +02:00
|
|
|
template = template.skip_cache().remove(non_existent_path)
|
2026-01-27 14:41:24 +01:00
|
|
|
_expect_to_throw_and_check_trace(lambda: build(template, name="remove"), "remove")
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skip_debug()
|
2025-10-01 14:37:58 +02:00
|
|
|
def test_traces_on_rename(build):
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
template = Template()
|
|
|
|
|
template = template.from_base_image()
|
2025-09-26 14:01:41 +02:00
|
|
|
template = template.skip_cache().rename(non_existent_path, "/tmp/dest.txt")
|
2026-01-27 14:41:24 +01:00
|
|
|
_expect_to_throw_and_check_trace(lambda: build(template, name="rename"), "rename")
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skip_debug()
|
2025-10-01 14:37:58 +02:00
|
|
|
def test_traces_on_make_dir(build):
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
template = Template()
|
|
|
|
|
template = template.from_base_image()
|
2025-10-15 12:26:35 +02:00
|
|
|
template = template.set_user("root").skip_cache().make_dir("/root/.bashrc")
|
2025-11-28 22:34:13 +01:00
|
|
|
_expect_to_throw_and_check_trace(
|
2026-01-27 14:41:24 +01:00
|
|
|
lambda: build(template, name="make_dir"), "make_dir"
|
2025-11-28 22:34:13 +01:00
|
|
|
)
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skip_debug()
|
2025-10-01 14:37:58 +02:00
|
|
|
def test_traces_on_make_symlink(build):
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
template = Template()
|
|
|
|
|
template = template.from_base_image()
|
2025-09-26 14:01:41 +02:00
|
|
|
template = template.skip_cache().make_symlink(".bashrc", ".bashrc")
|
2025-11-28 22:34:13 +01:00
|
|
|
_expect_to_throw_and_check_trace(
|
2026-01-27 14:41:24 +01:00
|
|
|
lambda: build(template, name="make_symlink"), "make_symlink"
|
2025-11-28 22:34:13 +01:00
|
|
|
)
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skip_debug()
|
2025-10-01 14:37:58 +02:00
|
|
|
def test_traces_on_run_cmd(build):
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
template = Template()
|
|
|
|
|
template = template.from_base_image()
|
2025-09-26 14:01:41 +02:00
|
|
|
template = template.skip_cache().run_cmd(f"cat {non_existent_path}")
|
2026-01-27 14:41:24 +01:00
|
|
|
_expect_to_throw_and_check_trace(lambda: build(template, name="run_cmd"), "run_cmd")
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skip_debug()
|
2025-10-01 14:37:58 +02:00
|
|
|
def test_traces_on_set_workdir(build):
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
template = Template()
|
|
|
|
|
template = template.from_base_image()
|
2025-10-15 12:26:35 +02:00
|
|
|
template = template.set_user("root").skip_cache().set_workdir("/root/.bashrc")
|
2025-11-28 22:34:13 +01:00
|
|
|
_expect_to_throw_and_check_trace(
|
2026-01-27 14:41:24 +01:00
|
|
|
lambda: build(template, name="set_workdir"), "set_workdir"
|
2025-11-28 22:34:13 +01:00
|
|
|
)
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skip_debug()
|
2025-10-01 14:37:58 +02:00
|
|
|
def test_traces_on_set_user(build):
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
template = Template()
|
|
|
|
|
template = template.from_base_image()
|
2025-10-15 12:26:35 +02:00
|
|
|
template = template.skip_cache().set_user("; exit 1")
|
2025-11-28 22:34:13 +01:00
|
|
|
_expect_to_throw_and_check_trace(
|
2026-01-27 14:41:24 +01:00
|
|
|
lambda: build(template, name="set_user"), "set_user"
|
2025-11-28 22:34:13 +01:00
|
|
|
)
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skip_debug()
|
2025-10-01 14:37:58 +02:00
|
|
|
def test_traces_on_pip_install(build):
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
template = Template()
|
|
|
|
|
template = template.from_base_image()
|
2025-09-26 14:01:41 +02:00
|
|
|
template = template.skip_cache().pip_install("nonexistent-package")
|
2025-11-28 22:34:13 +01:00
|
|
|
_expect_to_throw_and_check_trace(
|
2026-01-27 14:41:24 +01:00
|
|
|
lambda: build(template, name="pip_install"), "pip_install"
|
2025-11-28 22:34:13 +01:00
|
|
|
)
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skip_debug()
|
2025-10-01 14:37:58 +02:00
|
|
|
def test_traces_on_npm_install(build):
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
template = Template()
|
|
|
|
|
template = template.from_base_image()
|
2025-09-26 14:01:41 +02:00
|
|
|
template = template.skip_cache().npm_install("nonexistent-package")
|
2025-11-28 22:34:13 +01:00
|
|
|
_expect_to_throw_and_check_trace(
|
2026-01-27 14:41:24 +01:00
|
|
|
lambda: build(template, name="npm_install"), "npm_install"
|
2025-11-28 22:34:13 +01:00
|
|
|
)
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skip_debug()
|
2025-10-01 14:37:58 +02:00
|
|
|
def test_traces_on_apt_install(build):
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
template = Template()
|
|
|
|
|
template = template.from_base_image()
|
2025-09-26 14:01:41 +02:00
|
|
|
template = template.skip_cache().apt_install("nonexistent-package")
|
2025-11-28 22:34:13 +01:00
|
|
|
_expect_to_throw_and_check_trace(
|
2026-01-27 14:41:24 +01:00
|
|
|
lambda: build(template, name="apt_install"), "apt_install"
|
2025-11-28 22:34:13 +01:00
|
|
|
)
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skip_debug()
|
2025-10-01 14:37:58 +02:00
|
|
|
def test_traces_on_git_clone(build):
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
template = Template()
|
|
|
|
|
template = template.from_base_image()
|
2025-09-26 14:01:41 +02:00
|
|
|
template = template.skip_cache().git_clone("https://github.com/repo.git")
|
2025-11-28 22:34:13 +01:00
|
|
|
_expect_to_throw_and_check_trace(
|
2026-01-27 14:41:24 +01:00
|
|
|
lambda: build(template, name="git_clone"), "git_clone"
|
2025-11-28 22:34:13 +01:00
|
|
|
)
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skip_debug()
|
2025-10-01 14:37:58 +02:00
|
|
|
def test_traces_on_set_start_cmd(build):
|
Render failed layer stack traces on build error (#901)
### Changelog
- Added traces for Python and JavaScript SDK.
- Added methods for stack trace collection, stack trace context
- Updated file upload mechanism for tracing
- Changed API handling to support throwing API errors with traces
> **Note**
> For functions like `aptInstall`, `fromRegistry` which call `.run` and
`.fromImage`, the stack trace has to be replaced so it throws correctly
from parent.
> **Note**
> There are no build logs in the trace, we can add this at later point.
### Examples
Keep in mind that the way the traces are rendered entirely depends on
environment (Bun, Node, Deno, Vitest, Pytest)
**Standard Python**
```
Traceback (most recent call last):
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module>
Template.build(
~~~~~~~~~~~~~~^
template,
^^^^^^^^^
...<2 lines>...
memory_mb=1024,
^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build
wait_for_build_finish(
~~~~~~~~~~~~~~~~~~~~~^
api_client,
^^^^^^^^^^^
...<4 lines>...
stack_traces=template._template._stack_traces,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module>
.run_cmd("cat non_existing_file.txt")
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Pytest**
```
[gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
.run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
# try:
> Template.build(
template,
alias=str(uuid4()),
cpu_count=1,
memory_mb=1024,
)
tests/sync/template_sync/test_stacktrace.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
e2b/template_sync/main.py:157: in build
wait_for_build_finish(
e2b/template_sync/build_api.py:199: in wait_for_build_finish
raise BuildException(error_message).with_traceback(stack_trace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
@pytest.mark.skip_debug()
def test_build():
template = (
Template()
.from_image("ubuntu:22.04")
> .run_cmd("cat non_existing_file.txt")
.set_workdir("/app")
.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000))
)
E e2b.template.exceptions.BuildException: failed to run command: exit status 1
tests/sync/template_sync/test_stacktrace.py:12: BuildException
========================================================== short test summary info ==========================================================
FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1
```
**Node**
```
node:internal/modules/run_main:104
triggerUncaughtException(
^
at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) {
name: 'BuildError'
}
Node.js v23.11.0
```
**Bun**
```
1 | export class BuildError extends Error {
2 | constructor(message: string, stackTrace?: string) {
3 | super(message)
^
BuildError: failed to run command: exit status 1
at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5
Bun v1.2.4 (macOS arm64)
```
**Vitest**
```
BuildError: failed to run command: exit status 1
❯ tests/template/trace.test.ts:8:6
6| const template = Template()
7| .fromImage('ubuntu:22.04')
8| .runCmd('cat folder/test.txt')
| ^
9| .setWorkdir('/app')
10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))
```
---------
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
|
|
|
template = Template()
|
|
|
|
|
template = template.from_base_image()
|
|
|
|
|
template = template.set_start_cmd(
|
|
|
|
|
f"./{non_existent_path}", wait_for_timeout(10_000)
|
|
|
|
|
)
|
2025-11-28 22:34:13 +01:00
|
|
|
_expect_to_throw_and_check_trace(
|
2026-01-27 14:41:24 +01:00
|
|
|
lambda: build(template, name="set_start_cmd"), "set_start_cmd"
|
2025-11-28 22:34:13 +01:00
|
|
|
)
|
Add mcp server prepull (#975)
Adds prepulling mcp server images to the SDK.
```typescript
export const template = Template()
.fromTemplate("mcp-gateway")
.betaAddMcpServer("arxiv")
await Template.build(template, {
alias: "arxiv-mcp-gateway",
cpuCount: 1,
memoryMB: 1024,
onBuildLogs: console.log,
});
```
```python
template = Template().from_template("mcp-gateway").beta_add_mcp_server("arxiv")
Template.build(
template,
alias="arxiv-mcp-gateway-v1",
cpu_count=1,
memory_mb=1024,
)
```
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Introduce beta methods to prepull MCP servers via mcp-gateway in JS
and Python templates, with typing, validation, and stacktrace-tested
errors.
>
> - **Template SDKs**
> - **JS**:
> - Add `Template.betaAddMcpServer(servers: McpServerName |
McpServerName[])` to run `mcp-gateway pull ...`.
> - Enforce base template check (`'mcp-gateway'`), throwing `BuildError`
with stack trace.
> - Introduce and export `McpServerName` type (from `../sandbox/mcp`).
> - **Python**:
> - Add `Template.beta_add_mcp_server(servers: Union[str, List[str]])`
to run `mcp-gateway pull ...`.
> - Enforce `'mcp-gateway'` base template; raise `BuildException` with
captured traceback.
> - **Tests**
> - Add stacktrace tests for `betaAddMcpServer` (JS) and
`beta_add_mcp_server` (Python async/sync).
> - **Release**
> - Changeset: patch bumps for `@e2b/python-sdk` and `e2b`.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
43b4a01ce3c856dff7def5ba6b706ee00eda0f84. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Joseph Lombrozo <joe.lombrozo@e2b.dev>
2025-10-20 14:52:30 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skip_debug()
|
Promote beta MCP features to main (#986)
<!-- CURSOR_SUMMARY -->
> [!NOTE]
> Promotes MCP to stable across JS/Python SDKs: add `mcp` config to
sandbox creation, auto-select MCP template, start gateway with token,
rename beta APIs to stable (`getMcpUrl`/`getMcpToken`, `addMcpServer`).
>
> - **JS SDK**:
> - **Sandbox creation**: `Sandbox.create` now accepts `opts.mcp`;
auto-selects `defaultMcpTemplate`, starts `mcp-gateway` with generated
token, and returns initialized sandbox.
> - **API opts**: Move `mcp` from `SandboxBetaCreateOpts` to
`SandboxOpts`; pass `mcp` through `SandboxApi.createSandbox`.
> - **Stable MCP APIs**: Rename `betaGetMcpUrl` -> `getMcpUrl`,
`betaGetMcpToken` -> `getMcpToken`.
> - **Template builder**: Rename `betaAddMcpServer` -> `addMcpServer`.
> - **Tests**: Update stacktrace tests to new method names.
> - **Python SDK**:
> - **Sandbox creation**: `AsyncSandbox.create`/`Sandbox.create` accept
`mcp`; auto-select MCP template when unset, start `mcp-gateway`, store
token.
> - **Stable MCP APIs**: Add `get_mcp_url`; rename `beta_get_mcp_token`
-> `get_mcp_token`.
> - **Types**: Minor signature tweaks (e.g., `secure` default handling).
> - **Tests**: Update stacktrace tests to new method names.
> - **Release**:
> - Changeset: minor version bumps for `@e2b/python-sdk` and `e2b`.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
9c673f80eee37e530d05c6becf5a4a3c492ac9f3. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2025-10-22 21:22:02 +02:00
|
|
|
def test_traces_on_add_mcp_server():
|
Add mcp server prepull (#975)
Adds prepulling mcp server images to the SDK.
```typescript
export const template = Template()
.fromTemplate("mcp-gateway")
.betaAddMcpServer("arxiv")
await Template.build(template, {
alias: "arxiv-mcp-gateway",
cpuCount: 1,
memoryMB: 1024,
onBuildLogs: console.log,
});
```
```python
template = Template().from_template("mcp-gateway").beta_add_mcp_server("arxiv")
Template.build(
template,
alias="arxiv-mcp-gateway-v1",
cpu_count=1,
memory_mb=1024,
)
```
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Introduce beta methods to prepull MCP servers via mcp-gateway in JS
and Python templates, with typing, validation, and stacktrace-tested
errors.
>
> - **Template SDKs**
> - **JS**:
> - Add `Template.betaAddMcpServer(servers: McpServerName |
McpServerName[])` to run `mcp-gateway pull ...`.
> - Enforce base template check (`'mcp-gateway'`), throwing `BuildError`
with stack trace.
> - Introduce and export `McpServerName` type (from `../sandbox/mcp`).
> - **Python**:
> - Add `Template.beta_add_mcp_server(servers: Union[str, List[str]])`
to run `mcp-gateway pull ...`.
> - Enforce `'mcp-gateway'` base template; raise `BuildException` with
captured traceback.
> - **Tests**
> - Add stacktrace tests for `betaAddMcpServer` (JS) and
`beta_add_mcp_server` (Python async/sync).
> - **Release**
> - Changeset: patch bumps for `@e2b/python-sdk` and `e2b`.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
43b4a01ce3c856dff7def5ba6b706ee00eda0f84. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Joseph Lombrozo <joe.lombrozo@e2b.dev>
2025-10-20 14:52:30 -07:00
|
|
|
# needs mcp-gateway as base template, without it no mcp servers can be added
|
|
|
|
|
_expect_to_throw_and_check_trace(
|
2025-11-06 15:50:02 +01:00
|
|
|
lambda: Template().from_base_image().skip_cache().add_mcp_server("exa"),
|
Promote beta MCP features to main (#986)
<!-- CURSOR_SUMMARY -->
> [!NOTE]
> Promotes MCP to stable across JS/Python SDKs: add `mcp` config to
sandbox creation, auto-select MCP template, start gateway with token,
rename beta APIs to stable (`getMcpUrl`/`getMcpToken`, `addMcpServer`).
>
> - **JS SDK**:
> - **Sandbox creation**: `Sandbox.create` now accepts `opts.mcp`;
auto-selects `defaultMcpTemplate`, starts `mcp-gateway` with generated
token, and returns initialized sandbox.
> - **API opts**: Move `mcp` from `SandboxBetaCreateOpts` to
`SandboxOpts`; pass `mcp` through `SandboxApi.createSandbox`.
> - **Stable MCP APIs**: Rename `betaGetMcpUrl` -> `getMcpUrl`,
`betaGetMcpToken` -> `getMcpToken`.
> - **Template builder**: Rename `betaAddMcpServer` -> `addMcpServer`.
> - **Tests**: Update stacktrace tests to new method names.
> - **Python SDK**:
> - **Sandbox creation**: `AsyncSandbox.create`/`Sandbox.create` accept
`mcp`; auto-select MCP template when unset, start `mcp-gateway`, store
token.
> - **Stable MCP APIs**: Add `get_mcp_url`; rename `beta_get_mcp_token`
-> `get_mcp_token`.
> - **Types**: Minor signature tweaks (e.g., `secure` default handling).
> - **Tests**: Update stacktrace tests to new method names.
> - **Release**:
> - Changeset: minor version bumps for `@e2b/python-sdk` and `e2b`.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
9c673f80eee37e530d05c6becf5a4a3c492ac9f3. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2025-10-22 21:22:02 +02:00
|
|
|
"add_mcp_server",
|
Add mcp server prepull (#975)
Adds prepulling mcp server images to the SDK.
```typescript
export const template = Template()
.fromTemplate("mcp-gateway")
.betaAddMcpServer("arxiv")
await Template.build(template, {
alias: "arxiv-mcp-gateway",
cpuCount: 1,
memoryMB: 1024,
onBuildLogs: console.log,
});
```
```python
template = Template().from_template("mcp-gateway").beta_add_mcp_server("arxiv")
Template.build(
template,
alias="arxiv-mcp-gateway-v1",
cpu_count=1,
memory_mb=1024,
)
```
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Introduce beta methods to prepull MCP servers via mcp-gateway in JS
and Python templates, with typing, validation, and stacktrace-tested
errors.
>
> - **Template SDKs**
> - **JS**:
> - Add `Template.betaAddMcpServer(servers: McpServerName |
McpServerName[])` to run `mcp-gateway pull ...`.
> - Enforce base template check (`'mcp-gateway'`), throwing `BuildError`
with stack trace.
> - Introduce and export `McpServerName` type (from `../sandbox/mcp`).
> - **Python**:
> - Add `Template.beta_add_mcp_server(servers: Union[str, List[str]])`
to run `mcp-gateway pull ...`.
> - Enforce `'mcp-gateway'` base template; raise `BuildException` with
captured traceback.
> - **Tests**
> - Add stacktrace tests for `betaAddMcpServer` (JS) and
`beta_add_mcp_server` (Python async/sync).
> - **Release**
> - Changeset: patch bumps for `@e2b/python-sdk` and `e2b`.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
43b4a01ce3c856dff7def5ba6b706ee00eda0f84. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Joseph Lombrozo <joe.lombrozo@e2b.dev>
2025-10-20 14:52:30 -07:00
|
|
|
)
|
2025-10-24 23:20:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skip_debug()
|
2025-10-25 00:34:45 +02:00
|
|
|
def test_traces_on_dev_container_prebuild(build):
|
2025-10-24 23:20:29 +02:00
|
|
|
template = Template()
|
|
|
|
|
template = template.from_template("devcontainer")
|
2025-10-25 00:34:45 +02:00
|
|
|
template = template.skip_cache().beta_dev_container_prebuild(non_existent_path)
|
|
|
|
|
_expect_to_throw_and_check_trace(
|
2026-01-27 14:41:24 +01:00
|
|
|
lambda: build(template, name="beta_dev_container_prebuild"),
|
2025-11-28 22:34:13 +01:00
|
|
|
"beta_dev_container_prebuild",
|
2025-10-25 00:34:45 +02:00
|
|
|
)
|
2025-10-24 23:20:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skip_debug()
|
2025-10-25 00:34:45 +02:00
|
|
|
def test_traces_on_set_dev_container_start(build):
|
2025-10-24 23:20:29 +02:00
|
|
|
template = Template()
|
|
|
|
|
template = template.from_template("devcontainer")
|
2025-10-25 00:34:45 +02:00
|
|
|
template = template.beta_set_dev_container_start(non_existent_path)
|
|
|
|
|
_expect_to_throw_and_check_trace(
|
2026-01-27 14:41:24 +01:00
|
|
|
lambda: build(template, name="beta_set_dev_container_start"),
|
2025-11-28 22:34:13 +01:00
|
|
|
"beta_set_dev_container_start",
|
2025-10-25 00:34:45 +02:00
|
|
|
)
|