Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
support overriding apiUrl directly (#948)
Joseph Lombrozo3e430f66a1fa
diff --git a/.changeset/new-houses-burn.md b/.changeset/new-houses-burn.mdnew file mode 100644index 000000000..0c7dd3894--- /dev/null+++ b/.changeset/new-houses-burn.md@@ -0,0 +1,6 @@+---+'e2b': patch+'@e2b/cli': patch+---++Support overriding apiUrl via E2B_API_URLdiff --git a/packages/js-sdk/src/connectionConfig.ts b/packages/js-sdk/src/connectionConfig.tsindex f0acd0088..edcb9ef22 100644--- a/packages/js-sdk/src/connectionConfig.ts+++ b/packages/js-sdk/src/connectionConfig.ts@@ -29,6 +29,12 @@ export interface ConnectionOpts {* @default E2B_DOMAIN // environment variable or `e2b.app`*/domain?: string+ /**+ * API Url to use for the API.+ * @internal+ * @default E2B_API_URL // environment variable or `https://api.${domain}`+ */+ apiUrl?: string/*** If true the SDK starts in the debug mode and connects to the local envd API server.* @internal@@ -78,15 +84,20 @@ export class ConnectionConfig {this.headers = opts?.headers || {}this.headers['User-Agent'] = `e2b-js-sdk/${version}`- this.apiUrl = this.debug- ? 'http://localhost:3000'- : `https://api.${this.domain}`+ this.apiUrl =+ opts?.apiUrl ||+ ConnectionConfig.apiUrl ||+ (this.debug ? 'http://localhost:3000' : `https://api.${this.domain}`)}private static get domain() {return getEnvVar('E2B_DOMAIN') || 'e2b.app'}+ private static get apiUrl() {+ return getEnvVar('E2B_API_URL')+ }+private static get debug() {return (getEnvVar('E2B_DEBUG') || 'false').toLowerCase() === 'true'}diff --git a/packages/js-sdk/tests/connectionConfig.test.ts b/packages/js-sdk/tests/connectionConfig.test.tsnew file mode 100644index 000000000..a5356e0b6--- /dev/null+++ b/packages/js-sdk/tests/connectionConfig.test.ts@@ -0,0 +1,51 @@+import { assert, test, beforeEach, afterEach } from 'vitest'+import { ConnectionConfig } from '../src/connectionConfig'++// Store original env vars to restore after tests+let originalEnv: { [key: string]: string | undefined }++beforeEach(() => {+ originalEnv = {+ E2B_API_URL: process.env.E2B_API_URL,+ E2B_DEBUG: process.env.E2B_DEBUG,+ }+})++afterEach(() => {+ // Restore original env vars+ Object.keys(originalEnv).forEach((key) => {+ if (originalEnv[key] === undefined) {+ delete process.env[key]+ } else {+ process.env[key] = originalEnv[key]+ }+ })+})++test('api_url defaults correctly', () => {+ // Ensure no env vars interfere+ delete process.env.E2B_API_URL+ delete process.env.E2B_DEBUG++ const config = new ConnectionConfig()+ assert.equal(config.apiUrl, 'https://api.e2b.app')+})++test('api_url in args', () => {+ const config = new ConnectionConfig({ apiUrl: 'http://localhost:8080' })+ assert.equal(config.apiUrl, 'http://localhost:8080')+})++test('api_url in env var', () => {+ process.env.E2B_API_URL = 'http://localhost:8080'++ const config = new ConnectionConfig()+ assert.equal(config.apiUrl, 'http://localhost:8080')+})++test('api_url has correct priority', () => {+ process.env.E2B_API_URL = 'http://localhost:1111'++ const config = new ConnectionConfig({ apiUrl: 'http://localhost:8080' })+ assert.equal(config.apiUrl, 'http://localhost:8080')+})diff --git a/packages/js-sdk/vitest.workspace.mts b/packages/js-sdk/vitest.workspace.mtsindex f74b400d7..3cf9cd16c 100644--- a/packages/js-sdk/vitest.workspace.mts+++ b/packages/js-sdk/vitest.workspace.mts@@ -6,7 +6,7 @@ export default defineWorkspace([{test: {include: ['tests/**/*.test.ts'],- exclude: ['tests/runtimes/**', 'tests/integration/**'],+ exclude: ['tests/runtimes/**', 'tests/integration/**', 'tests/connectionConfig.test.ts'],isolate: false, // for projects that don't rely on side effects, disabling isolation will improve the speed of the testsglobals: false,testTimeout: 30_000,@@ -61,4 +61,13 @@ export default defineWorkspace([environment: 'node',},},+ {+ test: {+ include: ['tests/connectionConfig.test.ts'],+ globals: false,+ isolate: true,+ testTimeout: 10_000,+ environment: 'node',+ },+ },])diff --git a/packages/python-sdk/.tool-versions b/packages/python-sdk/.tool-versionsdeleted file mode 100644index 7ee935b98..000000000--- a/packages/python-sdk/.tool-versions+++ /dev/null@@ -1,2 +0,0 @@-python 3.9.24-poetry 1.8.3