Commit Graph

183 Commits

Author SHA1 Message Date
Mish Ushakov 5e9c6d6780 feat: validate copy src paths are relative and within context directory (#1106)
Add path validation to the copy method in both JS and Python SDKs to
ensure source paths are always relative and don't escape the context
directory.

This prevents:
- Absolute paths like /absolute/whatever (Unix) or C:\whatever (Windows)
- Path traversal attacks like ../whatever or ./foo/../../../bar

The validation works cross-platform using Node's
path.isAbsolute/normalize and Python's os.path.isabs/normpath plus
PureWindowsPath for detecting Windows paths on Unix.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Changes behavior of `copy`/`copy_items` to throw earlier for
previously-accepted absolute or escaping paths, which could break some
consumers; logic is localized and well-covered by tests.
> 
> **Overview**
> Prevents path traversal in template `copy` operations by validating
`src` is *relative* and does not escape the context directory (rejects
absolute paths and `..`-based escapes) in both the JS and Python SDKs.
> 
> Updates `copyItems`/`copy_items` error handling to preserve the
caller’s stack trace when validation fails, adds unit coverage for the
new path validator plus new stack-trace tests for absolute-path
failures, and ships as patch releases via a changeset.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
c1a8eb978e3fd99fa829d571e811bb7ee18cd40b. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 13:54:54 +01:00
Matt Brockman 1a8fed012c fix: Improve sandbox.git async/sync parity (#1110)
Fixes issue with missing `restore` and `reset` functionality on the
async git sandboxes.
 
Consolidate shared git helpers by moving remote URL argument
construction and
parsing into the git utilities package. Sync and async git modules now
reuse
the same builders where possible, with tests to ensure no drift.

---------

Co-authored-by: Filip Brebera <filip@bxxf.dev>
2026-02-03 11:58:16 -08:00
Matt Brockman 77b08f53e1 Feature: Add Git Support (#1101)
# Sandbox Git Commands

Adds Git support to the sandbox class. This allows the sandbox to manage
git via standard clone, checkout, branch, add, pull, and push commands
without needing to use commands.run. The API mirrors common Git
workflows while handling sandbox-specific concerns like auth injection
and safe remote handling.

**Python example**
```python
from e2b import Sandbox

sandbox = Sandbox.create()
repo_path = '/home/user/my-repo'

# Optional: set author for commits
sandbox.git.configure_user('Your Name', 'you@example.com')

# Clone or init
sandbox.git.clone('https://github.com/org/repo.git', path=repo_path)
# or
sandbox.git.init(repo_path, initial_branch='main')

# Make a change
sandbox.files.write(f'{repo_path}/README.md', '# Hello\n')

# Commit
sandbox.git.add(repo_path, files=['README.md'])
sandbox.git.commit(repo_path, message='Initial commit')

# Branching
sandbox.git.create_branch(repo_path, 'feature1')
# or
sandbox.git.checkout_branch(repo_path, 'main')

# Push
sandbox.git.remote_add(repo_path, 'origin', 'https://github.com/org/repo.git', overwrite=True)
sandbox.git.push(repo_path, remote='origin', branch='main', set_upstream=True)
```

**JavaScript / TypeScript example**
```ts
import { Sandbox } from 'e2b'

const sandbox = await Sandbox.create()
const repoPath = '/home/user/my-repo'

await sandbox.git.configureUser('Your Name', 'you@example.com')

await sandbox.git.clone('https://github.com/org/repo.git', { path: repoPath })
// or
await sandbox.git.init(repoPath, { initialBranch: 'main' })

await sandbox.files.write(`${repoPath}/README.md`, '# Hello\n')

await sandbox.git.add(repoPath, { files: ['README.md'] })
await sandbox.git.commit(repoPath, { message: 'Initial commit' })

await sandbox.git.createBranch(repoPath, 'feature1')
await sandbox.git.checkoutBranch(repoPath, 'main')

await sandbox.git.remoteAdd(repoPath, 'origin', 'https://github.com/org/repo.git', {
  overwrite: true,
})
await sandbox.git.push(repoPath, { remote: 'origin', branch: 'main', setUpstream: true })
```

**Main commands**
- `clone`: Clone a repo into the sandbox. Supports `branch`, `depth`,
optional `username` + `password` for private repos, and
`dangerously_store_credentials` / `dangerouslyStoreCredentials` to keep
credentials in the remote URL.
- `init`: Initialize a new repo. Supports `initial_branch` /
`initialBranch` and `bare`.
- `status`: Get parsed `git status --porcelain -b` info.
- `branches`: List branches and current branch.
- `create_branch` / `createBranch`: Create and check out a new branch.
- `checkout_branch` / `checkoutBranch`: Switch to an existing branch.
- `delete_branch` / `deleteBranch`: Delete a branch. Supports `force`.
- `add`: Stage files. Supports explicit files or `all`.
- `commit`: Create a commit. Supports author override and `allow_empty`.
- `reset` / `reset`: Reset `HEAD` (supports modes like `soft`, `mixed`,
`hard`, etc.) and optional paths.
- `restore` / `restore`: Restore files or unstage changes (`worktree` /
`staged`) from a source ref.
- `pull`: Pull from a remote. Supports `remote`, `branch`, and optional
auth.
- `push`: Push to a remote. Supports `remote`, `branch`, `set_upstream`,
and optional auth.
- `remote_add` / `remoteAdd`: Add a remote. Supports `overwrite` and
`fetch`.
- `remote_get` / `remoteGet`: Read a remote URL.
- `set_config` / `setConfig`: Set a git config value. Supports `scope`
(`global`, `local`, `system`), and `path` for local scope.
- `get_config` / `getConfig`: Read a git config value. Supports the same
`scope` options and returns `None` / `undefined` if unset.
- `dangerously_authenticate` / `dangerouslyAuthenticate`: Persist
credentials via the git credential helper (global).
- `configure_user` / `configureUser`: Set default `user.name` and
`user.email` for commits.
- `create_github_repo` (Python only): Create a GitHub repo from inside
the sandbox and optionally add it as a remote.

**Status shape**
- `status` returns a `GitStatus` with `current_branch` /
`currentBranch`, `upstream`, `ahead`, `behind`, `detached`, and
`file_status` / `fileStatus`.
- `file_status` entries include `name`, `status`, `index_status` /
`indexStatus`, `working_tree_status` / `workingTreeStatus`, `staged`,
and optional `renamed_from` / `renamedFrom`.
- Convenience helpers include: `is_clean` / `isClean`, `has_changes` /
`hasChanges`, `has_staged` / `hasStaged`, `has_untracked` /
`hasUntracked`, `has_conflicts` / `hasConflicts`, plus counts
(`total_count` / `totalCount`, `staged_count` / `stagedCount`,
`unstaged_count` / `unstagedCount`, `untracked_count` /
`untrackedCount`, `conflict_count` / `conflictCount`). In Python these
are properties on the `GitStatus` object; in JS they are fields on the
returned object.

**Notes**
- For private HTTPS remotes, pass `username` + `password` (token) on
`clone`, `pull`, or `push`.
- Use `remote_add` / `remoteAdd` with `overwrite=True` to update an
existing remote URL and `fetch=True` to fetch after.
- Use `dangerously_authenticate` / `dangerouslyAuthenticate` only when
you want to persist credentials globally on the sandbox.
2026-01-29 11:13:15 -08:00
Mish Ushakov 4af9b4c3fc Avoid reading files on upload (#1098)
<!-- CURSOR_SUMMARY -->
> [!NOTE]
> Optimizes file uploads in both JS and Python SDKs to avoid unnecessary
reads and add broader input support.
> 
> - JS SDK: `Filesystem.write`/`writeFiles` now build a single
`FormData` using `toBlob` (new util) to pass
`string`/`ArrayBuffer`/`Blob`/`ReadableStream` without pre-reading;
updated tests add `ReadableStream` coverage
> - Python SDK (sync/async): `write_files` accepts `str`/`bytes`
directly, reads `TextIOBase`, and passes `IOBase` (binary) streams
through without reading; new tests cover `BytesIO` and `StringIO`
> - Changeset: patch bumps for `@e2b/python-sdk` and `e2b`
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
45516e31fa8ba8b678824a6c1adc217287a8effe. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2026-01-27 15:30:38 -08:00
Mish Ushakov 07ef17f1b0 Rename alias exists > name exists (#1100) 2026-01-27 21:53:37 +01:00
Jakub Dobry 10abab8e96 feat: add template versioning with tags support for JS and Python SDKs (#1080) 2026-01-27 13:41:24 +00:00
Berry c1ee183769 Add writeFiles function to js sdk (#1084)
To fix the inconsistency between the Python SDK and the JS SDK, add
writeFiles to the JS SDK. (no changes made to write function)

---------

Co-authored-by: Mish Ushakov <10400064+mishushakov@users.noreply.github.com>
2026-01-23 15:28:37 +00:00
Jakub Novák ab906adcd3 Fix metrics timestamps (#1083)
<!-- CURSOR_SUMMARY -->
> [!NOTE]
> Aligns metrics APIs to use Unix seconds (no milliseconds) for
`start`/`end` across SDKs.
> 
> - **JS SDK**: `SandboxMetricsOpts` `start`/`end` now `Date` only;
convert to seconds before calling `GET /sandboxes/{sandboxID}/metrics`.
> - **Python SDK (async/sync)**: send `int(timestamp())` for
`start`/`end` instead of milliseconds.
> - **Tests**: JS and Python tests now pass `start`/`end` and validate
non-empty results.
> - **Changesets**: patch notes for `e2b` and `@e2b/python-sdk`.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
7c59f8023fc0de9a5eda7ffd4c588057c7465f3e. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2026-01-15 08:32:27 -08:00
Mish Ushakov 47fb2ef11d SandboxId-clientId pattern references (#1081)
Remove references to the `sandboxId-clientId` pattern as it is no longer
in use.

We're also converting the long sandbox id's in the API already:
https://github.com/e2b-dev/infra/blob/main/packages/api/internal/handlers/sandbox_get.go#L27

---
<a
href="https://cursor.com/background-agent?bcId=bc-e3bed60d-6524-431f-bce8-4934ddcc81d7"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/open-in-cursor-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/open-in-cursor-light.svg"><img alt="Open in
Cursor"
src="https://cursor.com/open-in-cursor.svg"></picture></a>&nbsp;<a
href="https://cursor.com/agents?id=bc-e3bed60d-6524-431f-bce8-4934ddcc81d7"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/open-in-web-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/open-in-web-light.svg"><img alt="Open in Web"
src="https://cursor.com/open-in-web.svg"></picture></a>

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Eliminates reliance on the deprecated `sandboxId-clientId` (short ID)
pattern and standardizes on full `sandboxId`.
> 
> - Removes `getShortID` and uses full `sandboxId` in `isRunning` (CLI
`utils.ts`), calling `Sandbox.getInfo` with the complete ID
> - Updates JS SDK tests to compare `sandboxId` via exact equality (no
`split`/`startsWith`) across list and pagination cases for
running/paused sandboxes
> - Updates Python SDK (async/sync) tests similarly to assert exact
`sandbox_id` equality in list and pagination scenarios
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
7ec60a51e5b22ed9b3e90aa46110c016ce0fd73a. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
2026-01-13 17:42:44 +01:00
Jiri Sveceny d8ef36d84f Support Template.aliasExists for JavaScript and Python SDKs (#1068)
Integration tests will fail until the feature is deployed in E2B Cloud
production.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Enables checking template alias availability from both SDKs.
> 
> - JS: Implements `checkAliasExists` in `template/buildApi.ts`, exposes
`Template.aliasExists` in `template/index.ts`, adds `AliasExistsOptions`
type and tests
> - Python: Adds `Template.alias_exists` and
`AsyncTemplate.alias_exists` wired to generated
`get_templates_aliases_{alias}` client; includes sync/async tests
> - API: Regenerates schemas/clients to include `GET
/templates/aliases/{alias}`, template build logs endpoint and
parameters, and supporting models (e.g., `TemplateAliasResponse`)
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
4e577fd77888478ac83b66db7537cd2355ea050b. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-12 10:05:48 +00:00
Mish Ushakov dc54fe0200 Parse chown on Docker COPY (#1071)
<!-- CURSOR_SUMMARY -->
> [!NOTE]
> Adds support for parsing ownership on file copy operations in
Dockerfile-based templates.
> 
> - JS: Update `dockerfileParser.ts` to treat `COPY/ADD` as
`ModifiableInstruction`, parse `--chown` via `instruction.getFlags()`,
and pass `user` to `templateBuilder.copy(src, dest, { user })`
> - Python: Update `_handle_copy_instruction` in `dockerfile_parser.py`
to extract `--chown=<user[:group]>` and pass `user` to
`template_builder.copy(src, dest, user=user)`
> - Tests: Add JS and Python (sync/async) tests verifying `COPY --chown`
parsing and argument propagation
> - Changeset: Patch releases for `@e2b/python-sdk` and `e2b`
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
9f3b151be18288bdcc41eaf37157b5d4572f0abf. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2026-01-09 23:29:40 +01:00
Tomas Valenta 2d5af16b05 Add PTY reconnect (#1053)
<!-- CURSOR_SUMMARY -->
> [!NOTE]
> Introduce `connect` methods to attach to running PTY sessions across
JS and Python SDKs, with tests and default timeout handling.
> 
> - **SDKs**:
>   - **JS (`packages/js-sdk/src/sandbox/commands/pty.ts`)**:
> - Add `Pty.connect(pid, opts?)` to attach to running PTYs; accepts
`PtyConnectOpts` with `onData`, `timeoutMs`, and `requestTimeoutMs`.
> - Factor default PTY connection timeout via
`defaultPtyConnectionTimeout` and apply to `create`/`connect` calls.
>   - **Python**:
> - Async: Add `AsyncSandbox.pty.connect(pid, on_data, timeout?,
request_timeout?)` in `e2b/sandbox_async/commands/pty.py`.
> - Sync: Add `sandbox.pty.connect(pid, timeout?, request_timeout?)` in
`e2b/sandbox_sync/commands/pty.py`.
> - **Tests**:
> - JS: `packages/js-sdk/tests/sandbox/pty/ptyConnect.test.ts` validates
connect/reconnect and output handling.
> - Python: async and sync tests under
`packages/python-sdk/tests/.../pty/test_pty_connect.py` verify
reconnection and exit codes.
> - **Release**:
> - Changeset: minor version bumps for `@e2b/python-sdk` and `e2b`; note
“added option to connect to a running pty session”.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
539c4f518606544dfcef253df5bde49354fe7903. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---------

Co-authored-by: Mish <10400064+mishushakov@users.noreply.github.com>
2025-12-22 17:46:35 +00:00
Mish Ushakov 482d20f6e7 Fix Python (sync) WatchHandle test (#1056)
<!-- CURSOR_SUMMARY -->
> [!NOTE]
> Adjusts the watch directory test to modify the file content and scan
returned events for a WRITE on the target file instead of asserting the
first event.
> 
> - **Tests (python-sdk)**:
> - Updates `tests/sync/sandbox_sync/files/test_watch.py`
`test_watch_directory_changes` to:
>     - Write updated content after `watch_dir` is started.
> - Iterate over `handle.get_new_events()` to find a
`FilesystemEventType.WRITE` for the target filename, asserting its
presence.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
f32678e4ed4b141ff9dc498fd9c655f374a66c76. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2025-12-22 17:34:35 +00:00
Mish Ushakov 7b687bddbb Fixes CMD parser in Python from_dockerfile method (#1040)
What was happening is that the following snippet:

```dockerfile
CMD ["sleep", "20"]
```

Was incorrectly converted to:

```
sleep, 20
```

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Fixes parsing of Dockerfile CMD/ENTRYPOINT array syntax to a proper
start command and updates tests accordingly.
> 
> - **Python SDK**:
> - `e2b/template/dockerfile_parser.py`: Parse CMD/ENTRYPOINT JSON array
(e.g., `["sleep", "20"]`) into a space-joined command (`sleep 20`) and
set as `start_cmd`.
> - **Tests**:
> - JS SDK and Python (sync/async): Add ENTRYPOINT case and assert
`startCmd`/`_start_cmd` equals `sleep 20`.
> - **Release**:
>   - Changeset: patch bump for `@e2b/python-sdk`.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
ed257ab11e618ece3e5fe70f232a3265fd857ad4. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2025-12-01 07:40:17 -08:00
Mish Ushakov d911c55c3e Improve CI/CD speed for template tests (#1035)
<!-- CURSOR_SUMMARY -->
> [!NOTE]
> Caches Playwright binaries in JS CI and refactors JS/Python template
tests to use API mocks and aliases, add Dockerfile tests, and update
install APIs to single-package calls.
> 
> - **CI**:
> - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in
`.github/workflows/js_sdk_tests.yml` to speed JS SDK tests.
> - **JS SDK Tests**:
> - Extend `buildTemplate` options to accept `alias` in
`tests/setup.ts`.
> - Add `fromDockerfile` tests and switch some builds to
`fromBaseImage`; add build-from-base-template test.
> - Update install method tests to single-package calls for
`aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`.
>   - Tweak `makeSymlink` test order to ensure overwrite behavior.
> - Overhaul stacktrace tests to use `msw` server mocks and alias-based
failure mapping.
> - **Python SDK Tests**:
>   - `build`/`async_build` fixtures accept optional `alias`.
> - Add `from_dockerfile` tests (sync/async); use base image/base
template where applicable.
>   - Update install method tests to single-package calls.
> - Rewrite stacktrace tests to monkeypatch API calls with alias-based
failure mapping.
> - **Dependencies**:
>   - Add dev dependency `msw` to `packages/js-sdk/package.json`.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
Mish Ushakov 6ff14f8b2e Add Windows CI to test matrix (#1020)
<!-- CURSOR_SUMMARY -->
> [!NOTE]
> Add Windows to CI matrices and make JS/Python utils and tests
cross-platform via path handling updates.
> 
> - **CI**:
> - Add Windows to test matrices in `cli_tests.yml`, `js_sdk_tests.yml`,
`python_sdk_tests.yml`; set bash shell/workdirs; disable fail-fast for
some jobs.
>   - Python CI runs `pytest -n 4` via Poetry.
> - **JS SDK**:
> - Path normalization for globbing (`normalizePath`) and use of
`Path.relativePosix()` in hashing and tar creation in
`src/template/utils.ts`.
> - **Python SDK**:
> - Add `normalize_path` and use forward-slash glob patterns in
`e2b/template/utils.py`.
> - **Tests**:
> - Make stack trace parsing robust to Windows paths; use `basename` in
file assertions; adjust Python tar tests tempdir fixture handling.
> - **Changeset**: add patch note for windows-related fixes.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
1b8dbe4a1af642dbcb86500837e93f7998b223f6. 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-11-26 09:50:26 -08:00
Mish Ushakov 8be34f8344 Fixes default Dockerfile user/workdir behavior (#1033)
Fixes issue https://github.com/e2b-dev/E2B/issues/1032

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Preserve Dockerfile USER/WORKDIR when provided and only apply E2B
defaults if absent, with tests and CLI fixtures updated accordingly.
> 
> - **Dockerfile parsing (SDKs)**:
> - **JS (`packages/js-sdk/src/template/dockerfileParser.ts`)**: Track
`USER`/`WORKDIR` usage and only set E2B defaults (`user`, `/home/user`)
if not specified; keep Docker defaults (`root`, `/`) initially.
> - **Python
(`packages/python-sdk/e2b/template/dockerfile_parser.py`)**: Same
behavior—preserve explicit `USER`/`WORKDIR`, fallback to defaults only
when absent.
> - **Tests**:
> - **JS**: Add tests for default vs. custom `USER`/`WORKDIR` in
`fromMethods.test.ts`.
> - **Python (async/sync)**: Add analogous tests in
`test_from_methods.py`.
> - **CLI template fixtures**:
> - Update expected outputs to remove redundant
`.set_user('user')`/`.set_workdir('/home/user')` when already specified;
minor ordering tweak for `.setStartCmd` in TS fixture.
> - **Changeset**:
> - Minor version bumps for `@e2b/python-sdk` and `e2b`; note: keep
Docker `WORKDIR` and `USER` if specified.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
1ce66362501932308292cef87b5d8a73012ee5f2. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2025-11-26 09:16:25 -08:00
Jakub Dobry 4c612888d4 feat: implement network out allow/deny list support (#1016) 2025-11-15 22:35:09 +00:00
Joseph Lombrozo 98d2c8c0a8 Ensure that httpx transport is reused across calls by default (#997)
This takes some shortcuts in order to keep backwards compatibility.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Reuses a singleton httpx transport/client across the SDK, introduces a
generic retry decorator for connect calls, and refactors code/tests to
use the shared clients and fixtures.
> 
> - **SDK (transport/client reuse)**
> - Add global `limits` (configurable via `E2B_*` env vars) and switch
`ApiClient` to accept `transport` instead of `limits`.
> - Introduce `e2b.api.client_async/client_sync` with `get_transport()`
(singleton) and `get_api_client()`; update `Sandbox`/`AsyncSandbox`,
paginators, and sandbox APIs to use them.
> - Remove per-class `_limits` from `SandboxBase`/`TemplateBase`; merge
extra headers correctly; pass `E2b-Sandbox-Port` as string.
> - Template build flows (sync/async) now reuse the API client's
underlying httpx client for file uploads.
> - **Connect client** (`e2b_connect/client.py`)
> - Add `_retry` decorator and apply to unary/server-stream methods;
simplify reconnection logic; minor typing/headers cleanups.
> - **Tests**
> - Add retry unit tests; introduce
`sandbox_factory`/`async_sandbox_factory` and a session `event_loop`;
refactor tests to use factories and shared transports; adjust tar
archive expectations.
> - **Misc**
>   - Add `.editorconfig`, CLI `.envrc`, and changeset entries.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
1d359231b63dc21b6c8d797886f7d6a77c9ed6b7. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---------

Co-authored-by: Tomas Valenta <valenta.and.thomas@gmail.com>
Co-authored-by: Mish <10400064+mishushakov@users.noreply.github.com>
2025-11-14 16:48:29 -08:00
Joseph Lombrozo d2e22e3748 Some general pytest cleanup (#1021)
- Individual tests must complete in less than 5 minutes
- Add a `make test` option that runs tests
- Upgrade poetry to 2.1.1 (the lock file was generated by this version,
so this just matches what we already expect)
2025-11-13 17:58:30 -08:00
Mish Ushakov 56d16a8762 Fix ignore files in file upload and added tests (#1012)
<!-- CURSOR_SUMMARY -->
> [!NOTE]
> Ensure file uploads honor ignore patterns (incl. .dockerignore),
refactor file discovery/tar streaming in JS/Python SDKs, and add
comprehensive tests.
> 
> - **File upload behavior**:
> - JS/TS and Python uploads now pass `ignorePatterns` (merged from
`fileIgnorePatterns` and `.dockerignore`) to tar creation, ensuring
ignored files aren’t uploaded.
> - **Refactor/Utilities**:
> - Rename `getAllFilesForFilesHash` -> `getAllFilesInPath` with
optional directory inclusion in both SDKs.
> - Implement `tar_file_stream` (JS and Python) to build archives from
`getAllFilesInPath`, with `noDirRecurse` and symlink control.
>   - Hashing functions updated to use `getAllFilesInPath`.
> - Type tweak: allow `None` in Python `stack_traces` during build wait.
> - **Integration**:
> - JS `uploadFile` and Python async/sync `upload_file` now use tar
streaming with ignore patterns; JS `Template` wires ignore patterns into
uploads.
> - **Tests**:
> - Add extensive tests for `getAllFilesInPath` and `tar_file_stream` in
JS and Python, covering ignore patterns, directories, sorting, and
symlinks.
>   - Remove obsolete tests relying on old function names.
> - **Meta**:
>   - Changeset entries for `@e2b/python-sdk` and `e2b` (patch).
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
2f83444f9006393f33e8c346bec1998b3a06044d. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2025-11-10 02:59:29 -08:00
Jakub Dobry 6b74009972 feat: add template background build helpers (#1011)
<!-- CURSOR_SUMMARY -->
> [!NOTE]
> Add background template build APIs and build status retrieval to
JS/Python SDKs, change build methods to return BuildInfo, and add tests.
> 
> - **JS SDK (templates)**:
> - Add `Template.buildInBackground` to start builds without waiting and
return `BuildInfo`.
> - Add `Template.getBuildStatus` with optional `logsOffset`; expose
`GetBuildStatusResponse`.
> - Change `Template.build` to return `BuildInfo` and then wait for
completion; refactor internal `build(...)` to accept `ApiClient` and
return identifiers.
> - Add types `AuthOptions`, `BuildInfo`, `GetBuildStatusOptions`; make
`logsOffset` optional in `getBuildStatus` input; update tests with
`backgroundBuild.test.ts`.
> - **Python SDK (templates)**:
> - Introduce `BuildInfo` dataclass;
`Template.build`/`AsyncTemplate.build` now return `BuildInfo`.
> - Add `Template.build_in_background` /
`AsyncTemplate.build_in_background` and `Template.get_build_status` /
`AsyncTemplate.get_build_status`; factor shared `_build`.
> - Export `BuildInfo` in `__init__.py`; add sync/async background build
tests.
> - **Meta**:
>   - Add changeset for patch releases.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
a47f70ea339f6ea2964714a122cde5b7cb5a891b. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2025-11-06 16:26:27 +01:00
Mish Ushakov 978fbed96f Improve cache hit consistency across environments (#1010) 2025-11-06 06:50:02 -08:00
Mish Ushakov 23adc93f5e Expand folder with double star pattern for recursive hash computation (#994)
Currently, when you provide a simple folder pattern like `folder/` to
copy() it will not check folders contents for changes (only the folder
metadata itself) which leads to stale caches.

This fix appends ** pattern when no pattern is specified for recursive
hash computation.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Ensure folder COPY patterns hash contents recursively to fix cache
invalidation, adding a shared file-gathering helper, tests, and a Python
glob dependency.
> 
> - **Template hashing (JS + Python SDKs)**:
> - Add `getAllFilesForFilesHash`
(`packages/js-sdk/src/template/utils.ts`) and
`get_all_files_for_files_hash`
(`packages/python-sdk/e2b/template/utils.py`) to collect directories and
nested files using glob patterns and ignores.
> - Update `calculateFilesHash`/`calculate_files_hash` to use the new
helpers, hashing recursive paths, metadata, and file contents; handle
symlinks consistently.
> - **Tests**:
> - Add comprehensive tests for recursive matching, ignore patterns,
sorting, empty dirs, symlinks in
`packages/js-sdk/tests/.../getAllFilesForFilesHash.test.ts` and Python
async/sync tests under
`packages/python-sdk/tests/.../test_get_all_files_for_files_hash.py`.
> - **Dependencies**:
> - Add `wcmatch` in `packages/python-sdk/pyproject.toml` for advanced
globbing.
> - **Release**:
>   - Patch bump via `.changeset/green-mice-watch.md`.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
d495427d86ad4e4d5a280567baa63df40a3271fb. 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-11-03 16:34:17 +01:00
Mish Ushakov e87576fb7c Dockerfile output - change ENV var syntax (#1004)
Current env var syntax won't be anymore supported by Docker and is
currently blocking local development.

```
3 warnings found (use docker --debug to expand):
 - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 2)
```

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Use "ENV key=value" in generated Dockerfiles and add tests; minor
devcontainer path string cast.
> 
> - **Template/Dockerfile generation**:
> - **JS SDK (`packages/js-sdk/src/template/index.ts`)**: Handle `ENV`
instructions and output as `ENV key=value ...`.
> - **Python SDK (`packages/python-sdk/e2b/template/main.py`)**: Same
`ENV` formatting; also cast `devcontainer_directory` to `str` in
devcontainer start command.
> - **Tests**:
>   - **JS**: Add `toDockerfile` test covering `ENV` output.
> - **Python (sync/async)**: Add tests for `ENV` output in generated
Dockerfiles.
> - **Changeset**: Patch releases for `@e2b/python-sdk` and `e2b`.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
4a9c504167dd8069551724d83bfa66f0859c1bd4. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2025-11-01 00:28:06 +01:00
Jakub Novák 742a9ba953 Update connect method (#1001)
<!-- CURSOR_SUMMARY -->
> [!NOTE]
> Use new connect API for JS/Python SDKs to connect and only extend
(never shorten) running sandbox timeouts, with updated types/docs and
tests.
> 
> - **SDKs**:
>   - **JS**:
> - Replace `resume`/`setTimeout` flow with `SandboxApi.connectSandbox`
calling `POST /sandboxes/{sandboxID}/connect`.
> - Update `Sandbox.connect` (static/instance) to use returned
`sandboxDomain`, `envdAccessToken`, `envdVersion`.
> - Redefine `SandboxConnectOpts` to include `timeoutMs` that only
extends existing timeout.
>   - **Python (async/sync)**:
> - Introduce `_cls_connect` using `post_sandboxes_sandbox_id_connect`
with `ConnectSandbox`; return `Sandbox` model.
> - Update `connect` methods to use API response for
domain/token/version; remove extra info fetch.
>     - Docstrings clarify timeout only extends for running sandboxes.
> - **Tests**:
> - Add cases ensuring connect does not shorten timeout and does extend
when longer (JS, async Python, sync Python).
>   - Preserve error on connecting to non-running sandbox.
> - **Meta**:
> - Changeset: minor releases for `@e2b/python-sdk`, `e2b`, and
`@e2b/cli`.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
e76b07990cb4c05e51ba1c51fb5cc7bbd44b991b. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2025-10-31 05:17:40 -07:00
Mish Ushakov e8576a51e6 Add .fromBunImage and .bunInstall to the SDK (#993)
<!-- CURSOR_SUMMARY -->
> [!NOTE]
> Adds `fromBunImage` and `bunInstall` to JS/Python SDKs, and extends
`npmInstall` with a `dev` flag, with tests across sync/async suites.
> 
> - **Template APIs**:
> - Add `fromBunImage` to start from `oven/bun:<variant>` in
`packages/js-sdk/src/template/index.ts` and
`packages/python-sdk/e2b/template/main.py`.
>   - Add `bunInstall(packages, { g, dev })` in both SDKs.
>   - Extend `npmInstall` to accept `{ dev: boolean }` in both SDKs.
> - **Types/Docs**:
> - Update `packages/js-sdk/src/template/types.ts` to declare
`fromBunImage`, `bunInstall`, and `npmInstall` `dev` option.
> - **Tests**:
> - Add tests for `fromBunImage` and `bunInstall` and update
`npmInstall` (global/dev) in JS (`packages/js-sdk/tests/...`) and Python
sync/async (`packages/python-sdk/tests/...`).
> - **Changeset**:
> - Minor releases for `@e2b/python-sdk` and `e2b`
(`.changeset/silly-lions-buy.md`).
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
b6461d015743d38ba014d724167d2ca256cf7951. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2025-10-28 16:59:37 +00:00
Jakub Dobry f593bb7004 fix: update dev container naming (#989) 2025-10-24 22:34:45 +00:00
Jakub Dobry 1fa99a3d20 feat: devcontainer template support (#988) 2025-10-24 14:20:29 -07:00
Mish Ushakov c432805161 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
Mish Ushakov 818e8c2647 Add force option to make symlink method (#984)
<!-- CURSOR_SUMMARY -->
> [!NOTE]
> Adds a force option to makeSymlink that passes -f to ln, with
typings/docs and tests across JS and Python SDKs.
> 
> - **Template symlink enhancement**
>   - **JS SDK (`packages/js-sdk`)**:
> - `makeSymlink(src, dest, options)` now accepts `{ user?: string;
force?: boolean }` and appends `-f` when `force` is true in
`src/template/index.ts`.
> - Types updated in `src/template/types.ts`, including example usage
with `{ force: true }`.
> - Tests added in `tests/template/methods/makeSymlink.test.ts` (regular
and forced).
>   - **Python SDK (`packages/python-sdk`)**:
> - `make_symlink(src, dest, user=None, force=False)` now supports
`force` and appends `-f` when true in `e2b/template/main.py`.
>     - Docstring examples updated to include `force=True`.
> - Tests added for async and sync in
`tests/async/template_async/methods/test_make_symlink.py` and
`tests/sync/template_sync/methods/test_make_symlink.py`.
> - **Release**:
>   - Changeset added for patch releases of `@e2b/python-sdk` and `e2b`.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
6c5bbf9edfc7234b703046f387d11b8f10a002ab. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2025-10-22 00:48:11 +02:00
Mish Ushakov de2a922aa5 Make no install recommends optional (#983)
This was causing some unexpected issues if users were trying to
apt-install some packages that needed recommended dependencies.

<!-- CURSOR_SUMMARY -->
> [!NOTE]
> Adds an option to `aptInstall`/`apt_install` to toggle
`--no-install-recommends`, updates typings/docs, and adds tests for both
modes.
> 
> - **Template APIs**:
>   - **JS SDK (`packages/js-sdk`)**:
> - `aptInstall` now accepts `options?: { noInstallRecommends?: boolean
}` and conditionally includes `--no-install-recommends`.
>     - Types updated in `src/template/types.ts` with example usage.
>   - **Python SDK (`packages/python-sdk`)**:
> - `apt_install` now accepts `no_install_recommends: bool = False` and
conditionally includes `--no-install-recommends`.
> - **Tests**:
> - JS: Add `aptInstall` tests (with and without `noInstallRecommends`);
refactor `npmInstall` tests to use `buildTemplateTest` helper.
> - Python: Add async and sync tests for `apt_install` with and without
`no_install_recommends`.
> - **Changeset**:
> - Patch bumps for `@e2b/python-sdk` and `e2b` with note on making
`--no-install-recommends` optional.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
3963b7daca73f1cfb99f405b09fbfb86c40c4b4f. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2025-10-21 14:59:57 -07:00
Mish Ushakov d4619f641b Fixes ubuntu default image tag and added tests (#982)
The "lts" tag was unavailable on Docker Hub

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Switch default Ubuntu image tag from 'lts' to 'latest' across
JS/Python SDKs and expand/refactor template tests and test config.
> 
> - **SDKs**:
> - **Ubuntu default**: Change `fromUbuntuImage`/`from_ubuntu_image`
default variant from `'lts'` to `'latest'` in
`packages/js-sdk/src/template/index.ts` and
`packages/python-sdk/e2b/template/main.py`; update TS docs in
`packages/js-sdk/src/template/types.ts`.
> - **Tests**:
> - **JS**: Refactor template tests to use `buildTemplateTest`, add
`tests/template/methods/fromMethods.test.ts`, adjust npm/pip/runCmd
tests (include user install with `g: false`), and remove per-test
timeouts where not needed.
> - **Python (async/sync)**: Add comprehensive tests for from* methods,
npm/pip installs (including user installs), and runCmd behaviors; switch
to shared build fixtures.
> - **Vitest config**: Exclude `tests/template/**` from the main suite
and include all template tests in a dedicated project in
`vitest.workspace.mts`.
> - **Changeset**:
>   - Patch bumps for `@e2b/python-sdk` and `e2b`.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
0bf3a7c15122d28cbc99b8faa44e7e217f634377. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2025-10-21 16:47:09 +02:00
Mish Ushakov 314bc14143 Test setup: append "e2b-test" to templates generated in tests (#981)
So that we ca distinguish templates in our team account that are built
from the CI tests.
2025-10-21 12:29:58 +00:00
Jonas Scholz 68abd92c40 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
Mish Ushakov 83243d5b43 Add user option to fs methods in Template (#976)
(no tests as nothin was breaking)


<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Adds an optional `user` parameter to fs-related template methods and
`gitClone`, with tests for running commands as specific users.
> 
> - **SDKs**:
>   - **JS (`packages/js-sdk`)**:
> - Add `user` option to `TemplateBuilder` methods: `remove`, `rename`,
`makeDir`, `makeSymlink`, and `gitClone`; pass through to `runCmd`.
>     - Update type defs and examples in `src/template/types.ts`.
>   - **Python (`packages/python-sdk`)**:
> - Add `user` arg to `TemplateBuilder` methods: `remove`, `rename`,
`make_dir`, `make_symlink`, and `git_clone`; forward to `run_cmd`.
>     - Update docstrings/examples.
> - **Tests**:
> - JS: add `runCmd` tests for default, specific `user`, and invalid
user in `packages/js-sdk/tests/template/methods/runCmd.test.ts`.
> - Python: add async and sync `run_cmd` tests (default, specific
`user`, invalid user) in
`packages/python-sdk/tests/async/.../test_run_cmd.py` and
`packages/python-sdk/tests/sync/.../test_run_cmd.py`.
> - **Release**:
> - Add changeset (`.changeset/warm-seals-design.md`) marking patch
bumps for `@e2b/python-sdk` and `e2b`.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
b0cbedc1d5c136367155c5646859842bd666b0d9. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2025-10-20 23:44:05 +02:00
Joseph Lombrozo 8c77cb04db Support overriding the api_url directly (#946)
This will help for local development

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Add support to override the API base URL via `api_url` parameter or
`E2B_API_URL` env var with clear precedence.
> 
> - **Python SDK**:
>   - **ConnectionConfig**:
> - Add `api_url` parameter and `_api_url()` env lookup (`E2B_API_URL`).
> - Resolve `api_url` in order: constructor arg > `E2B_API_URL` >
`debug` localhost or `https://api.<domain>`.
>   - **API Params**:
> - Include `api_url` in `ApiParams` and propagate via `get_api_params`.
>   - **Tests** (`packages/python-sdk/tests/test_connection_config.py`):
>     - Verify default, arg override, env override, and precedence.
> - **Changeset**: Patch release for `@e2b/python-sdk`.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
9be6d4e85bb0ad8ea52ad61c77530ac72f231c54. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2025-10-20 11:53:19 -07:00
Jonas Scholz cc595f3fc8 Revert timeout changes in tests (#973) 2025-10-20 00:25:50 +02:00
Mish Ushakov c47927f1d0 Fix .toDocker RUN and COPY handling (#972)
<!-- CURSOR_SUMMARY -->
> [!NOTE]
> Fix Dockerfile generation to properly render `RUN` and `COPY`
instructions using only relevant args, and add patch changesets.
> 
> - **Template to Dockerfile generation**:
> - JS (`packages/js-sdk/src/template/index.ts`): Special-case `RUN` and
`COPY` so Dockerfile emits `RUN <cmd>` and `COPY <src> <dest>` instead
of joining all args.
> - Python (`packages/python-sdk/e2b/template/main.py`): Same
special-casing for `RUN` and `COPY` during Dockerfile rendering.
> - **Release**:
> - Changeset: patch bumps for `@e2b/python-sdk` and `e2b` with note
"fix RUN and COPY handling in to_dockerfile".
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
04b2dbbda34f0845f3d4ec9963cc478b7b7b7f01. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2025-10-18 19:35:22 +02:00
Jonas Scholz d7d55df930 Add mcp to request body (#961)
<!-- CURSOR_SUMMARY -->
> [!NOTE]
> Adds `mcp` config support for sandbox creation across API, JS, and
Python SDKs, and updates timeout tests to use explicit request timeouts.
> 
> - **API/OpenAPI**:
> - Add `McpConfig` schema and `mcp` field to `NewSandbox` in
`spec/openapi.yml` and generated TS `schema.gen.ts`.
> - **JS SDK**:
> - `SandboxApi.createSandbox` sends `mcp` in POST body
(`packages/js-sdk/src/sandbox/sandboxApi.ts`).
>   - Types updated to include `components["schemas"]["McpConfig"]`.
> - **Python SDK**:
> - Extend `NewSandbox` model and sandbox create flow to accept/pass
`mcp`; async/sync APIs propagate `mcp` to POST `/sandboxes`.
> - **Tests**:
> - Increase `is_running` request timeouts in timeout tests to reduce
flakiness (JS and Python).
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
04ad4e6d4947e33523b74aba2f703fa1e9c05e72. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2025-10-17 12:31:32 -07:00
Mish Ushakov d877205874 Implement stack traces override context for fromDockerfile (#959)
<!-- CURSOR_SUMMARY -->
> [!NOTE]
> Adds a stack trace override context so fromDockerfile errors point to
the caller; enables related tests and bumps patch versions.
> 
> - **Template stack traces**:
>   - JS (`packages/js-sdk/src/template/index.ts`):
>     - Add `stackTracesOverride` and `runInStackTraceOverrideContext`.
> - `fromDockerfile` parses within override using
`getCallerFrame(STACK_TRACE_DEPTH - 1)`.
>     - `collectStackTrace` respects override.
>   - Python (`packages/python-sdk/e2b/template/main.py`):
> - Add `_stack_traces_override` and
`_run_in_stack_trace_override_context`.
> - `from_dockerfile` parses within override using caller frame-derived
`TracebackType`.
>     - `_collect_stack_trace` respects override.
> - **Tests**:
> - Enable stack trace expectations for `fromTemplate` and
`fromDockerfile` in JS and Python (sync/async) stacktrace tests.
> - **Release**:
>   - Patch bumps for `@e2b/python-sdk` and `e2b`.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
ef0db209ea968b2cedb39cd56b82f637ede3e4e0. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2025-10-15 09:31:50 -07:00
Jakub Dobry 3046491ea9 feat: set default user and workdir when using Dockerfile (#954)
Set default user for Dockerfiles. Includes also small migrate fixes.



<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Defaults Dockerfile-based templates to user 'user' and workdir
'/home/user', updates CLI templates (sudo start/ready, relative Python
import), and allows template migration without a config file.
> 
> - **SDKs (Dockerfile parsing)**:
> - JS (`packages/js-sdk/src/template/dockerfileParser.ts`) and Python
(`packages/python-sdk/e2b/template/dockerfile_parser.py`): after
parsing, set defaults `setUser('user')` and `setWorkdir('/home/user')`.
> - **CLI Templates**:
> - Python build scripts: switch to relative import `from .template
import template`.
> - Generated template hbs: start/ready commands now prefixed with
`sudo`; removed explicit root/workdir before start/ready.
> - **CLI Migrate**:
> - Supports migration without `e2b.toml`; uses default config values
and prints a warning instead of exiting.
> - Initializes default config when missing; success messaging adjusted.
> - **Tests**:
> - Update fixtures to reflect new defaults (`set_user('user')`,
`set_workdir('/home/user')`, `sudo` start/ready, relative imports).
>   - Relax error case to succeed with warning when config is missing.
> - Comment out stacktrace tests for `fromDockerfile` in JS/Python until
fixed.
> - **Changesets**: Patch bumps for `@e2b/cli`, `@e2b/python-sdk`, and
`e2b`.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
934dc3b23b5607f70d4a4f5b7a9413a9d04df28a. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2025-10-15 05:51:40 -07:00
Jakub Dobry 86786e578f fix: template tests after infra update (#956)
<!-- CURSOR_SUMMARY -->
> [!NOTE]
> Updates stacktrace tests to use root-owned paths for workdir/dir ops
and a more explicit failing set_user command in JS and Python
(async/sync) SDKs.
> 
> - **Tests (stacktrace)**:
>   - **JS SDK (`packages/js-sdk/tests/template/stacktrace.test.ts`)**:
> - `setWorkdir`: set user to `root` and change path to `/root/.bashrc`.
>     - `setUser`: use `; exit 1` as the failing command.
>   - **Python SDK**:
> - Async
(`packages/python-sdk/tests/async/template_async/test_stacktrace.py`):
> - `make_dir`, `set_workdir`: set user to `root` and target
`/root/.bashrc`.
>       - `set_user`: use `; exit 1` as the failing command.
> - Sync
(`packages/python-sdk/tests/sync/template_sync/test_stacktrace.py`):
> - `make_dir`, `set_workdir`: set user to `root` and target
`/root/.bashrc`.
>       - `set_user`: use `; exit 1` as the failing command.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
780023b3819f19ba908ccd794195e630bab2741b. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2025-10-15 03:26:35 -07:00
Mish Ushakov c40eeaac38 Improve regex for fileContextPath (#939)
<!-- CURSOR_SUMMARY -->
> [!NOTE]
> Improve stack-trace path parsing for caller directory and add
JS/Python tests; publish as patch.
> 
> - **Template utils (JS SDK)**:
> - Add `matchFileDir` to robustly extract file directory from
stack-trace lines (handles anonymous frames).
> - Refactor `getCallerDirectory` to use `matchFileDir` for path
parsing.
> - **Tests**:
>   - Add JS tests for `getCallerDirectory` and `matchFileDir`.
>   - Add Python async/sync tests for `get_caller_directory`.
> - **Release**:
>   - Add changeset marking a patch for `e2b`.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
6bd8aa7353479c1657f63c99c732faee042f4c06. 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-10 12:27:40 +00:00
Mish Ushakov faeeb78a3c Skip cache before image in TypeScript (#937)
<!-- CURSOR_SUMMARY -->
> [!NOTE]
> Adjusts `skipCache` to return `this` in types and aligns
implementation for proper fluent chaining.
> 
> - **JS SDK – `template`**:
> - **Types**: Change `skipCache` return type from `TemplateBuilder` to
`this` in `types.ts` (`TemplateFromImage`, `TemplateBuilder`).
> - **Implementation**: Align `skipCache` in `index.ts` by removing
explicit return type annotation to match `this` chaining.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
58131d1e5c8caaddc3a23523f99c069ac00a32a7. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2025-10-09 16:25:47 +00:00
Jakub Dobry a01c2374a9 feat: pretty default logs for build helper (#925) 2025-10-09 05:44:03 -07:00
Mish Ushakov edfcc63076 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
Mish Ushakov b1e2701931 Correct file hashing logic in the SDK (#916)
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-10-01 05:37:58 -07:00
Jakub Novák e142c23c31 Set stdin to /dev/null by default (#919)
Disable stdin (setting it to `/dev/null` for `command.run()`, but enable
to setting it to pipe, which you can send the input via
`command.sendStdin()`
This fixes issues with tools checking for stdin and then hanging
indefinitely

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Disables stdin by default and introduces a new `StartRequest.stdin`
flag to opt-in to stdin piping, updating JS/Python SDKs, version gating,
and tests.
> 
> - **Spec/Protobuf**:
> - Add `optional bool stdin` to `process.StartRequest` in
`spec/envd/process/process.proto` and regenerate JS/Python protos.
> - **JS SDK**:
> - Add `ENVD_COMMANDS_STDIN = '0.3.0'` and version check; error if
`stdin === false` on older envd.
> - Extend `CommandStartOpts` with `stdin` (default `false`); pass
`stdin` to `rpc.start`.
> - **Python SDK**:
> - Add `ENVD_COMMANDS_STDIN = Version("0.3.0")` and version check
mirroring JS.
> - Extend async/sync `commands.run()` with `stdin` (default `False`);
pass to `StartRequest`.
>   - Update generated `process_pb2`/`.pyi` with `StartRequest.stdin`.
> - **Tests**:
> - Update send-stdin tests to run commands with `stdin:
true`/`stdin=True`.
> - **Changeset**:
>   - Minor bump for `@e2b/python-sdk` and `e2b`.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
458a15187e6eadccd43540e6b8972c4d45e1bb78. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2025-09-29 05:34:16 -07:00
Jakub Dobry 1c34e5dd0b fix: npm install and pip install helpers (#923) 2025-09-29 05:33:46 -07:00