Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
ci(code-interpreter-js): run the full suite under Bun, Deno and Cloudflare instead of smoke tests (#1771)
devin-ai-integration[bot]84cabc26204a
diff --git a/.changeset/olive-pans-shave.md b/.changeset/olive-pans-shave.mdnew file mode 100644index 000000000..0e4a14a9d--- /dev/null+++ b/.changeset/olive-pans-shave.md@@ -0,0 +1,5 @@+---+'@e2b/code-interpreter': patch+---++Detect a mid-request sandbox kill on Deno, where the disconnect surfaces as a bare `TypeError` message instead of a socket error code, so `runCode` throws the descriptive `TimeoutError` there toodiff --git a/.changeset/plain-eyes-clap.md b/.changeset/plain-eyes-clap.mdnew file mode 100644index 000000000..8bf512805--- /dev/null+++ b/.changeset/plain-eyes-clap.md@@ -0,0 +1,5 @@+---+'@e2b/code-interpreter': patch+---++Detect a mid-request sandbox kill on Cloudflare Workers, where workerd reports the disconnect as `Network connection lost.` instead of a socket error code, so `runCode` throws the descriptive `TimeoutError` there toodiff --git a/.github/workflows/code_interpreter_js_tests.yml b/.github/workflows/code_interpreter_js_tests.ymlindex 55a6c8a75..9b3dcc21d 100644--- a/.github/workflows/code_interpreter_js_tests.yml+++ b/.github/workflows/code_interpreter_js_tests.yml@@ -11,6 +11,11 @@ on:required: falsetype: booleandefault: true+ node-only:+ description: 'Run only the Node leg (skip Bun, Deno and Cloudflare)'+ required: false+ type: boolean+ default: falsesecrets:E2B_API_KEY:required: true@@ -24,7 +29,18 @@ jobs:run:working-directory: ./packages/code-interpreter-jsshell: bash- name: Code Interpreter JS SDK - Build and test+ name: Code Interpreter JS SDK - ${{ matrix.runtime }}+ strategy:+ fail-fast: false+ # With node-only (set by staging callers) the matrix collapses to the+ # Node leg: the other legs re-run the suite the Node leg already covers+ # and add sandbox load without extra backend signal, so the other+ # runtimes are exercised against production only.+ matrix:+ runtime: >-+ ${{ inputs.node-only+ && fromJSON('["node"]')+ || fromJSON('["node", "bun", "deno", "cloudflare"]') }}runs-on: ubuntu-22.04steps:- name: Checkout repository@@ -64,35 +80,30 @@ jobs:- name: Test buildrun: pnpm build- - name: Run Node tests- run: |- if [[ "${{ inputs.run_recovery_tests }}" == "true" ]]; then- pnpm test- else- pnpm test --exclude tests/interrupt.test.ts --exclude tests/systemd.test.ts- fi- env:- E2B_API_KEY: ${{ secrets.E2B_API_KEY }}- E2B_DOMAIN: ${{ inputs.E2B_DOMAIN }}-- name: Install Bun+ if: matrix.runtime == 'bun'uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0- with:- bun-version: '${{ env.TOOL_VERSION_BUN }}'-- - name: Run Bun tests- run: pnpm test:bun- env:- E2B_API_KEY: ${{ secrets.E2B_API_KEY }}- E2B_DOMAIN: ${{ inputs.E2B_DOMAIN }}- name: Install Deno+ if: matrix.runtime == 'deno'uses: denoland/setup-deno@22d081ff2d3a40755e97629de92e3bcbfa7cf2ed # v2.0.5with:deno-version: 'v${{ env.TOOL_VERSION_DENO }}'- - name: Run Deno tests- run: pnpm test:deno+ # The recovery suites (interrupt, systemd) exercise sandbox recovery+ # paths that staging cannot serve, so callers can opt out of them.+ - name: Run test suite under ${{ matrix.runtime }}+ run: |+ case "${{ matrix.runtime }}" in+ node) script=test ;;+ cloudflare) script=test:cf ;;+ *) script=test:${{ matrix.runtime }} ;;+ esac+ if [[ "${{ inputs.run_recovery_tests }}" == "true" ]]; then+ pnpm "$script"+ else+ pnpm "$script" --exclude tests/interrupt.test.ts --exclude tests/systemd.test.ts+ fienv:E2B_API_KEY: ${{ secrets.E2B_API_KEY }}E2B_DOMAIN: ${{ inputs.E2B_DOMAIN }}diff --git a/.github/workflows/sdk_tests.yml b/.github/workflows/sdk_tests.ymlindex 02d5360ee..7c8443217 100644--- a/.github/workflows/sdk_tests.yml+++ b/.github/workflows/sdk_tests.yml@@ -181,6 +181,9 @@ jobs:with:E2B_DOMAIN: ${{ vars.E2B_DOMAIN_STAGING }}run_recovery_tests: false+ # Staging only checks backend compatibility, so the Node leg suffices;+ # Bun/Deno runtime coverage runs against production above.+ node-only: truesecrets:E2B_API_KEY: ${{ secrets.E2B_API_KEY_STAGING }}diff --git a/packages/code-interpreter-js/deno.lock b/packages/code-interpreter-js/deno.lockdeleted file mode 100644index d662608f5..000000000--- a/packages/code-interpreter-js/deno.lock+++ /dev/null@@ -1,53 +0,0 @@-{- "version": "5",- "remote": {- "https://deno.land/[email protected]/assert/_constants.ts": "a271e8ef5a573f1df8e822a6eb9d09df064ad66a4390f21b3e31f820a38e0975",- "https://deno.land/[email protected]/assert/assert.ts": "09d30564c09de846855b7b071e62b5974b001bb72a4b797958fe0660e7849834",- "https://deno.land/[email protected]/assert/assert_almost_equals.ts": "9e416114322012c9a21fa68e187637ce2d7df25bcbdbfd957cd639e65d3cf293",- "https://deno.land/[email protected]/assert/assert_array_includes.ts": "14c5094471bc8e4a7895fc6aa5a184300d8a1879606574cb1cd715ef36a4a3c7",- "https://deno.land/[email protected]/assert/assert_equals.ts": "3bbca947d85b9d374a108687b1a8ba3785a7850436b5a8930d81f34a32cb8c74",- "https://deno.land/[email protected]/assert/assert_exists.ts": "43420cf7f956748ae6ed1230646567b3593cb7a36c5a5327269279c870c5ddfd",- "https://deno.land/[email protected]/assert/assert_false.ts": "3e9be8e33275db00d952e9acb0cd29481a44fa0a4af6d37239ff58d79e8edeff",- "https://deno.land/[email protected]/assert/assert_greater.ts": "5e57b201fd51b64ced36c828e3dfd773412c1a6120c1a5a99066c9b261974e46",- "https://deno.land/[email protected]/assert/assert_greater_or_equal.ts": "9870030f997a08361b6f63400273c2fb1856f5db86c0c3852aab2a002e425c5b",- "https://deno.land/[email protected]/assert/assert_instance_of.ts": "e22343c1fdcacfaea8f37784ad782683ec1cf599ae9b1b618954e9c22f376f2c",- "https://deno.land/[email protected]/assert/assert_is_error.ts": "f856b3bc978a7aa6a601f3fec6603491ab6255118afa6baa84b04426dd3cc491",- "https://deno.land/[email protected]/assert/assert_less.ts": "60b61e13a1982865a72726a5fa86c24fad7eb27c3c08b13883fb68882b307f68",- "https://deno.land/[email protected]/assert/assert_less_or_equal.ts": "d2c84e17faba4afe085e6c9123a63395accf4f9e00150db899c46e67420e0ec3",- "https://deno.land/[email protected]/assert/assert_match.ts": "ace1710dd3b2811c391946954234b5da910c5665aed817943d086d4d4871a8b7",- "https://deno.land/[email protected]/assert/assert_not_equals.ts": "78d45dd46133d76ce624b2c6c09392f6110f0df9b73f911d20208a68dee2ef29",- "https://deno.land/[email protected]/assert/assert_not_instance_of.ts": "3434a669b4d20cdcc5359779301a0588f941ffdc2ad68803c31eabdb4890cf7a",- "https://deno.land/[email protected]/assert/assert_not_match.ts": "df30417240aa2d35b1ea44df7e541991348a063d9ee823430e0b58079a72242a",- "https://deno.land/[email protected]/assert/assert_not_strict_equals.ts": "37f73880bd672709373d6dc2c5f148691119bed161f3020fff3548a0496f71b8",- "https://deno.land/[email protected]/assert/assert_object_match.ts": "411450fd194fdaabc0089ae68f916b545a49d7b7e6d0026e84a54c9e7eed2693",- "https://deno.land/[email protected]/assert/assert_rejects.ts": "4bee1d6d565a5b623146a14668da8f9eb1f026a4f338bbf92b37e43e0aa53c31",- "https://deno.land/[email protected]/assert/assert_strict_equals.ts": "b4f45f0fd2e54d9029171876bd0b42dd9ed0efd8f853ab92a3f50127acfa54f5",- "https://deno.land/[email protected]/assert/assert_string_includes.ts": "496b9ecad84deab72c8718735373feb6cdaa071eb91a98206f6f3cb4285e71b8",- "https://deno.land/[email protected]/assert/assert_throws.ts": "c6508b2879d465898dab2798009299867e67c570d7d34c90a2d235e4553906eb",- "https://deno.land/[email protected]/assert/assertion_error.ts": "ba8752bd27ebc51f723702fac2f54d3e94447598f54264a6653d6413738a8917",- "https://deno.land/[email protected]/assert/equal.ts": "bddf07bb5fc718e10bb72d5dc2c36c1ce5a8bdd3b647069b6319e07af181ac47",- "https://deno.land/[email protected]/assert/fail.ts": "0eba674ffb47dff083f02ced76d5130460bff1a9a68c6514ebe0cdea4abadb68",- "https://deno.land/[email protected]/assert/mod.ts": "48b8cb8a619ea0b7958ad7ee9376500fe902284bb36f0e32c598c3dc34cbd6f3",- "https://deno.land/[email protected]/assert/unimplemented.ts": "8c55a5793e9147b4f1ef68cd66496b7d5ba7a9e7ca30c6da070c1a58da723d73",- "https://deno.land/[email protected]/assert/unreachable.ts": "5ae3dbf63ef988615b93eb08d395dda771c96546565f9e521ed86f6510c29e19",- "https://deno.land/[email protected]/dotenv/mod.ts": "0180eaeedaaf88647318811cdaa418cc64dc51fb08354f91f5f480d0a1309f7d",- "https://deno.land/[email protected]/dotenv/parse.ts": "09977ff88dfd1f24f9973a338f0f91bbdb9307eb5ff6085446e7c423e4c7ba0c",- "https://deno.land/[email protected]/dotenv/stringify.ts": "275da322c409170160440836342eaa7cf012a1d11a7e700d8ca4e7f2f8aa4615",- "https://deno.land/[email protected]/fmt/colors.ts": "508563c0659dd7198ba4bbf87e97f654af3c34eb56ba790260f252ad8012e1c5",- "https://deno.land/[email protected]/internal/diff.ts": "6234a4b493ebe65dc67a18a0eb97ef683626a1166a1906232ce186ae9f65f4e6",- "https://deno.land/[email protected]/internal/format.ts": "0a98ee226fd3d43450245b1844b47003419d34d210fa989900861c79820d21c2",- "https://deno.land/[email protected]/internal/mod.ts": "534125398c8e7426183e12dc255bb635d94e06d0f93c60a297723abe69d3b22e"- },- "workspace": {- "packageJson": {- "dependencies": [- "npm:@types/node@^20.19.19",- "npm:@typescript/typescript6@^6.0.2",- "npm:dotenv@^16.4.5",- "npm:tsdown@~0.22.14",- "npm:typescript@^7.0.2",- "npm:vitest@^4.1.10"- ]- }- }-}diff --git a/packages/code-interpreter-js/package.json b/packages/code-interpreter-js/package.jsonindex 3c69d9198..279053925 100644--- a/packages/code-interpreter-js/package.json+++ b/packages/code-interpreter-js/package.json@@ -29,15 +29,17 @@"dev": "tsdown --watch","test": "vitest run","test:coverage": "vitest run --coverage",- "test:bun": "bun test tests/runtimes/bun --env-file=.env",- "test:deno": "deno test tests/runtimes/deno/ --import-map tests/runtimes/deno/import_map.json --allow-net --allow-read --allow-env --unstable-sloppy-imports --trace-leaks",+ "test:bun": "bunx --bun vitest run",+ "test:deno": "deno run -A ./node_modules/vitest/vitest.mjs run",+ "test:cf": "vitest run --config tests/runtimes/cloudflare/vitest.config.mts","typecheck": "tsc --noEmit","lint": "oxlint --config ../../.oxlintrc.json src tests","format": "prettier --write src/ tests/"},"devDependencies": {- "@typescript/native": "catalog:",+ "@cloudflare/vitest-pool-workers": "^0.18.7","@types/node": "catalog:",+ "@typescript/native": "catalog:","dotenv": "^16.4.5","tsdown": "catalog:","typescript": "catalog:",diff --git a/packages/code-interpreter-js/src/utils.ts b/packages/code-interpreter-js/src/utils.tsindex 060458e41..1bb8ff29b 100644--- a/packages/code-interpreter-js/src/utils.ts+++ b/packages/code-interpreter-js/src/utils.ts@@ -22,11 +22,20 @@ export function formatExecutionTimeoutError(error: unknown) {const CONNECTION_CLOSED_CODES = ['ECONNRESET', 'EPIPE', 'UND_ERR_SOCKET']+// Deno (hyper) and workerd surface a mid-stream disconnect as a plain error+// with no `code` and no `cause` — the message is the only signal.+const CONNECTION_CLOSED_MESSAGES = [+ 'error reading a body from connection',+ 'connection closed before message completed',+ 'connection reset by peer',+ 'network connection lost',+]+/*** Checks if the error means the connection was closed/reset while the request- * was in flight. The shape of this error is runtime-specific — Bun and Deno- * set a `code` directly, while Node's fetch (undici) wraps the socket error- * in the `cause` of a generic `TypeError`.+ * was in flight. The shape of this error is runtime-specific — Bun sets a+ * `code` directly, Node's fetch (undici) wraps the socket error in the `cause`+ * of a generic `TypeError`, and Deno and workerd only set a message.*/export function isConnectionClosedError(error: unknown): boolean {if (!(error instanceof Error)) {@@ -42,6 +51,11 @@ export function isConnectionClosedError(error: unknown): boolean {return true}+ const message = error.message.toLowerCase()+ if (CONNECTION_CLOSED_MESSAGES.some((m) => message.includes(m))) {+ return true+ }+if (error.cause) {return isConnectionClosedError(error.cause)}diff --git a/packages/code-interpreter-js/tests/runtimes/bun/run.test.ts b/packages/code-interpreter-js/tests/runtimes/bun/run.test.tsdeleted file mode 100644index 71ee3e145..000000000--- a/packages/code-interpreter-js/tests/runtimes/bun/run.test.ts+++ /dev/null@@ -1,18 +0,0 @@-import { expect, test } from 'bun:test'--import { Sandbox } from '../../../src'--test(- 'Bun test',- async () => {- const sbx = await Sandbox.create({ timeoutMs: 5_000 })-- try {- const result = await sbx.runCode('print("Hello, World!")')- expect(result.logs.stdout.join('')).toEqual('Hello, World!\n')- } finally {- await sbx.kill()- }- },- { timeout: 30_000 }-)diff --git a/packages/code-interpreter-js/tests/runtimes/cloudflare/vitest.config.mts b/packages/code-interpreter-js/tests/runtimes/cloudflare/vitest.config.mtsnew file mode 100644index 000000000..226e6139e--- /dev/null+++ b/packages/code-interpreter-js/tests/runtimes/cloudflare/vitest.config.mts@@ -0,0 +1,43 @@+import { cloudflareTest } from '@cloudflare/vitest-pool-workers'+import { config } from 'dotenv'+import { defineConfig } from 'vitest/config'++const env = config()++// Runs the same suite the node/bun/deno legs run, but inside Cloudflare's+// workerd via vitest-pool-workers, against src.+export default defineConfig({+ plugins: [+ cloudflareTest({+ miniflare: {+ compatibilityDate: '2026-03-01',+ // nodejs_compat is a hard requirement for the SDK on Workers. It also+ // mirrors the bindings below into process.env (default since compat+ // date 2025-04-01), which is how tests and the SDK read E2B_*.+ compatibilityFlags: ['nodejs_compat'],+ bindings: {+ E2B_API_KEY: process.env.E2B_API_KEY ?? env.parsed?.E2B_API_KEY ?? '',+ E2B_DOMAIN: process.env.E2B_DOMAIN ?? env.parsed?.E2B_DOMAIN ?? '',+ },+ },+ }),+ ],+ test: {+ name: 'cloudflare',+ include: ['tests/**/*.test.ts'],+ globals: false,+ testTimeout: 30_000,+ bail: 0,+ // workerd reports a rejection as unhandled unless a handler is attached+ // within the same microtask drain, so the stream teardown of a sandbox the+ // test kills (or interrupts) mid-request is reported even though the test+ // awaits it. Drop only those two shapes; anything else still fails the run.+ onUnhandledError(error) {+ const message = String(error.message ?? '')+ const expectedRejection =+ error.type === 'Unhandled Rejection' &&+ (message === 'Network connection lost.' || error.name === 'AbortError')+ if (expectedRejection) return false+ },+ },+})diff --git a/packages/code-interpreter-js/tests/runtimes/deno/import_map.json b/packages/code-interpreter-js/tests/runtimes/deno/import_map.jsondeleted file mode 100644index 8e7ab64b1..000000000--- a/packages/code-interpreter-js/tests/runtimes/deno/import_map.json+++ /dev/null@@ -1,5 +0,0 @@-{- "imports": {- "e2b": "../../../../js-sdk/dist/index.mjs"- }-}diff --git a/packages/code-interpreter-js/tests/runtimes/deno/run.test.ts b/packages/code-interpreter-js/tests/runtimes/deno/run.test.tsdeleted file mode 100644index c84d0fa85..000000000--- a/packages/code-interpreter-js/tests/runtimes/deno/run.test.ts+++ /dev/null@@ -1,17 +0,0 @@-import { assertEquals } from 'https://deno.land/[email protected]/assert/mod.ts'-import { load } from 'https://deno.land/[email protected]/dotenv/mod.ts'--await load({ envPath: '.env', export: true })--import { Sandbox } from '../../../dist/index.mjs'--Deno.test('Deno test', async () => {- const sbx = await Sandbox.create({ timeoutMs: 5_000 })-- try {- const result = await sbx.runCode('print("Hello, World!")')- assertEquals(result.logs.stdout.join(''), 'Hello, World!\n')- } finally {- await sbx.kill()- }-})diff --git a/packages/js-sdk/package.json b/packages/js-sdk/package.jsonindex 46d3485e4..8fd66d1a6 100644--- a/packages/js-sdk/package.json+++ b/packages/js-sdk/package.json@@ -38,7 +38,7 @@"test:bun": "bunx --bun vitest run --project unit --project connectionConfig --project template","test:cf": "vitest run --config tests/runtimes/cloudflare/vitest.config.mts","test:cf:deploy": "vitest run --config tests/runtimes/cloudflare-deploy/vitest.config.mts",- "test:deno": "deno run -A npm:vitest run --project unit --project connectionConfig --project template",+ "test:deno": "deno run -A ./node_modules/vitest/vitest.mjs run --project unit --project connectionConfig --project template","typecheck": "tsc --noEmit","lint": "oxlint --config ../../.oxlintrc.json src tests","format": "prettier --write src/ tests/"diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 276345a39..655dcf703 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -181,6 +181,9 @@ importers:specifier: workspace:^version: link:../js-sdkdevDependencies:+ '@cloudflare/vitest-pool-workers':+ specifier: ^0.18.7+ version: 0.18.7(@types/[email protected])(@vitest/[email protected])(@vitest/[email protected])([email protected])([email protected])([email protected])'@types/node':specifier: 'catalog:'version: 20.19.43