From e1e7a5f1446784c576da0336ee166b778017dd05 Mon Sep 17 00:00:00 2001 From: Mish Ushakov <10400064+mishushakov@users.noreply.github.com> Date: Mon, 13 Apr 2026 17:23:51 +0200 Subject: [PATCH 1/7] Add language autocomplete for js, ts, r, java, bash Co-Authored-By: Claude Opus 4.6 --- .changeset/add-language-overloads.md | 6 +++ js/src/sandbox.ts | 27 +------------ .../code_interpreter_async.py | 38 +------------------ .../code_interpreter_sync.py | 38 +------------------ 4 files changed, 12 insertions(+), 97 deletions(-) create mode 100644 .changeset/add-language-overloads.md diff --git a/.changeset/add-language-overloads.md b/.changeset/add-language-overloads.md new file mode 100644 index 00000000..0a1f00bd --- /dev/null +++ b/.changeset/add-language-overloads.md @@ -0,0 +1,6 @@ +--- +"@e2b/code-interpreter": patch +"e2b-code-interpreter": patch +--- + +Add autocomplete support for javascript, typescript, r, java, and bash languages in runCode/run_code and createCodeContext/create_code_context diff --git a/js/src/sandbox.ts b/js/src/sandbox.ts index a02b9d9e..59a716a4 100644 --- a/js/src/sandbox.ts +++ b/js/src/sandbox.ts @@ -88,7 +88,7 @@ export interface CreateCodeContextOpts { * * @default python */ - language?: string + language?: 'python' | 'javascript' | 'typescript' | 'r' | 'java' | 'bash' | (string & {}) /** * Timeout for the request in **milliseconds**. * @@ -128,29 +128,6 @@ export class Sandbox extends BaseSandbox { )}` } - /** - * Run the code as Python. - * - * Specify the `language` or `context` option to run the code as a different language or in a different `Context`. - * - * You can reference previously defined variables, imports, and functions in the code. - * - * @param code code to execute. - * @param opts options for executing the code. - * - * @returns `Execution` result object. - */ - async runCode( - code: string, - opts?: RunCodeOpts & { - /** - * Language to use for code execution. - * - * If not defined, the default Python context is used. - */ - language?: 'python' - } - ): Promise /** * Run the code for the specified language. * @@ -172,7 +149,7 @@ export class Sandbox extends BaseSandbox { * * If not defined, the default Python context is used. */ - language?: string + language?: 'python' | 'javascript' | 'typescript' | 'r' | 'java' | 'bash' | (string & {}) } ): Promise /** diff --git a/python/e2b_code_interpreter/code_interpreter_async.py b/python/e2b_code_interpreter/code_interpreter_async.py index de938240..e9788bc8 100644 --- a/python/e2b_code_interpreter/code_interpreter_async.py +++ b/python/e2b_code_interpreter/code_interpreter_async.py @@ -68,41 +68,7 @@ def _client(self) -> AsyncClient: async def run_code( self, code: str, - language: Union[Literal["python"], None] = None, - on_stdout: Optional[OutputHandlerWithAsync[OutputMessage]] = None, - on_stderr: Optional[OutputHandlerWithAsync[OutputMessage]] = None, - on_result: Optional[OutputHandlerWithAsync[Result]] = None, - on_error: Optional[OutputHandlerWithAsync[ExecutionError]] = None, - envs: Optional[Dict[str, str]] = None, - timeout: Optional[float] = None, - request_timeout: Optional[float] = None, - ) -> Execution: - """ - Runs the code as Python. - - Specify the `language` or `context` option to run the code as a different language or in a different `Context`. - - You can reference previously defined variables, imports, and functions in the code. - - :param code: Code to execute - :param language: Language to use for code execution. If not defined, the default Python context is used. - :param on_stdout: Callback for stdout messages - :param on_stderr: Callback for stderr messages - :param on_result: Callback for the `Result` object - :param on_error: Callback for the `ExecutionError` object - :param envs: Custom environment variables - :param timeout: Timeout for the code execution in **seconds** - :param request_timeout: Timeout for the request in **seconds** - - :return: `Execution` result object - """ - ... - - @overload - async def run_code( - self, - code: str, - language: Optional[str] = None, + language: Union[Literal["python", "javascript", "typescript", "r", "java", "bash"], str, None] = None, on_stdout: Optional[OutputHandlerWithAsync[OutputMessage]] = None, on_stderr: Optional[OutputHandlerWithAsync[OutputMessage]] = None, on_result: Optional[OutputHandlerWithAsync[Result]] = None, @@ -236,7 +202,7 @@ async def run_code( async def create_code_context( self, cwd: Optional[str] = None, - language: Optional[str] = None, + language: Union[Literal["python", "javascript", "typescript", "r", "java", "bash"], str, None] = None, request_timeout: Optional[float] = None, ) -> Context: """ diff --git a/python/e2b_code_interpreter/code_interpreter_sync.py b/python/e2b_code_interpreter/code_interpreter_sync.py index 3adb2804..5e3e4422 100644 --- a/python/e2b_code_interpreter/code_interpreter_sync.py +++ b/python/e2b_code_interpreter/code_interpreter_sync.py @@ -65,41 +65,7 @@ def _client(self) -> Client: def run_code( self, code: str, - language: Union[Literal["python"], None] = None, - on_stdout: Optional[OutputHandler[OutputMessage]] = None, - on_stderr: Optional[OutputHandler[OutputMessage]] = None, - on_result: Optional[OutputHandler[Result]] = None, - on_error: Optional[OutputHandler[ExecutionError]] = None, - envs: Optional[Dict[str, str]] = None, - timeout: Optional[float] = None, - request_timeout: Optional[float] = None, - ) -> Execution: - """ - Runs the code as Python. - - Specify the `language` or `context` option to run the code as a different language or in a different `Context`. - - You can reference previously defined variables, imports, and functions in the code. - - :param code: Code to execute - :param language: Language to use for code execution. If not defined, the default Python context is used. - :param on_stdout: Callback for stdout messages - :param on_stderr: Callback for stderr messages - :param on_result: Callback for the `Result` object - :param on_error: Callback for the `ExecutionError` object - :param envs: Custom environment variables - :param timeout: Timeout for the code execution in **seconds** - :param request_timeout: Timeout for the request in **seconds** - - :return: `Execution` result object - """ - ... - - @overload - def run_code( - self, - code: str, - language: Optional[str] = None, + language: Union[Literal["python", "javascript", "typescript", "r", "java", "bash"], str, None] = None, on_stdout: Optional[OutputHandler[OutputMessage]] = None, on_stderr: Optional[OutputHandler[OutputMessage]] = None, on_result: Optional[OutputHandler[Result]] = None, @@ -232,7 +198,7 @@ def run_code( def create_code_context( self, cwd: Optional[str] = None, - language: Optional[str] = None, + language: Union[Literal["python", "javascript", "typescript", "r", "java", "bash"], str, None] = None, request_timeout: Optional[float] = None, ) -> Context: """ From 935ecb7f23a7efd19819f46b208d59e2399d0695 Mon Sep 17 00:00:00 2001 From: Mish Ushakov <10400064+mishushakov@users.noreply.github.com> Date: Mon, 13 Apr 2026 19:29:35 +0200 Subject: [PATCH 2/7] Fix eslint ban-types error for string & {} Use NonNullable instead of {} to satisfy @typescript-eslint/ban-types. Co-Authored-By: Claude Opus 4.6 --- js/src/sandbox.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/src/sandbox.ts b/js/src/sandbox.ts index 59a716a4..26025ce5 100644 --- a/js/src/sandbox.ts +++ b/js/src/sandbox.ts @@ -88,7 +88,7 @@ export interface CreateCodeContextOpts { * * @default python */ - language?: 'python' | 'javascript' | 'typescript' | 'r' | 'java' | 'bash' | (string & {}) + language?: 'python' | 'javascript' | 'typescript' | 'r' | 'java' | 'bash' | (string & NonNullable) /** * Timeout for the request in **milliseconds**. * @@ -149,7 +149,7 @@ export class Sandbox extends BaseSandbox { * * If not defined, the default Python context is used. */ - language?: 'python' | 'javascript' | 'typescript' | 'r' | 'java' | 'bash' | (string & {}) + language?: 'python' | 'javascript' | 'typescript' | 'r' | 'java' | 'bash' | (string & NonNullable) } ): Promise /** From 46a7fcc54062e9ff816d9ecd8a03b42a861a7bbc Mon Sep 17 00:00:00 2001 From: Mish Ushakov <10400064+mishushakov@users.noreply.github.com> Date: Mon, 13 Apr 2026 19:30:33 +0200 Subject: [PATCH 3/7] Simplify language type to plain string union Co-Authored-By: Claude Opus 4.6 --- js/src/sandbox.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/src/sandbox.ts b/js/src/sandbox.ts index 26025ce5..761701e7 100644 --- a/js/src/sandbox.ts +++ b/js/src/sandbox.ts @@ -88,7 +88,7 @@ export interface CreateCodeContextOpts { * * @default python */ - language?: 'python' | 'javascript' | 'typescript' | 'r' | 'java' | 'bash' | (string & NonNullable) + language?: 'python' | 'javascript' | 'typescript' | 'r' | 'java' | 'bash' | string /** * Timeout for the request in **milliseconds**. * @@ -149,7 +149,7 @@ export class Sandbox extends BaseSandbox { * * If not defined, the default Python context is used. */ - language?: 'python' | 'javascript' | 'typescript' | 'r' | 'java' | 'bash' | (string & NonNullable) + language?: 'python' | 'javascript' | 'typescript' | 'r' | 'java' | 'bash' | string } ): Promise /** From 81780fed885825194b1945ca09569eb09b31e0a7 Mon Sep 17 00:00:00 2001 From: Mish Ushakov <10400064+mishushakov@users.noreply.github.com> Date: Mon, 13 Apr 2026 19:31:48 +0200 Subject: [PATCH 4/7] Use string & {} with eslint-disable for language autocomplete Co-Authored-By: Claude Opus 4.6 --- js/src/sandbox.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/js/src/sandbox.ts b/js/src/sandbox.ts index 761701e7..cbd5c78a 100644 --- a/js/src/sandbox.ts +++ b/js/src/sandbox.ts @@ -88,7 +88,8 @@ export interface CreateCodeContextOpts { * * @default python */ - language?: 'python' | 'javascript' | 'typescript' | 'r' | 'java' | 'bash' | string + // eslint-disable-next-line @typescript-eslint/ban-types + language?: 'python' | 'javascript' | 'typescript' | 'r' | 'java' | 'bash' | (string & {}) /** * Timeout for the request in **milliseconds**. * @@ -149,7 +150,8 @@ export class Sandbox extends BaseSandbox { * * If not defined, the default Python context is used. */ - language?: 'python' | 'javascript' | 'typescript' | 'r' | 'java' | 'bash' | string + // eslint-disable-next-line @typescript-eslint/ban-types + language?: 'python' | 'javascript' | 'typescript' | 'r' | 'java' | 'bash' | (string & {}) } ): Promise /** From 53fdd42992deb4027de56547cda6c3c9c0c21053 Mon Sep 17 00:00:00 2001 From: Mish Ushakov <10400064+mishushakov@users.noreply.github.com> Date: Mon, 13 Apr 2026 19:34:07 +0200 Subject: [PATCH 5/7] Format sandbox.ts with prettier Co-Authored-By: Claude Opus 4.6 --- js/src/sandbox.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/js/src/sandbox.ts b/js/src/sandbox.ts index cbd5c78a..7738e09b 100644 --- a/js/src/sandbox.ts +++ b/js/src/sandbox.ts @@ -89,7 +89,14 @@ export interface CreateCodeContextOpts { * @default python */ // eslint-disable-next-line @typescript-eslint/ban-types - language?: 'python' | 'javascript' | 'typescript' | 'r' | 'java' | 'bash' | (string & {}) + language?: + | 'python' + | 'javascript' + | 'typescript' + | 'r' + | 'java' + | 'bash' + | (string & {}) /** * Timeout for the request in **milliseconds**. * @@ -151,7 +158,14 @@ export class Sandbox extends BaseSandbox { * If not defined, the default Python context is used. */ // eslint-disable-next-line @typescript-eslint/ban-types - language?: 'python' | 'javascript' | 'typescript' | 'r' | 'java' | 'bash' | (string & {}) + language?: + | 'python' + | 'javascript' + | 'typescript' + | 'r' + | 'java' + | 'bash' + | (string & {}) } ): Promise /** From 97f712f31cef15c49aa872cee9daae044548f761 Mon Sep 17 00:00:00 2001 From: Mish Ushakov <10400064+mishushakov@users.noreply.github.com> Date: Mon, 13 Apr 2026 19:36:26 +0200 Subject: [PATCH 6/7] Use eslint-disable/enable block for ban-types on multiline type Co-Authored-By: Claude Opus 4.6 --- js/src/sandbox.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/js/src/sandbox.ts b/js/src/sandbox.ts index 7738e09b..5d12b93a 100644 --- a/js/src/sandbox.ts +++ b/js/src/sandbox.ts @@ -88,7 +88,7 @@ export interface CreateCodeContextOpts { * * @default python */ - // eslint-disable-next-line @typescript-eslint/ban-types + /* eslint-disable @typescript-eslint/ban-types */ language?: | 'python' | 'javascript' @@ -97,6 +97,7 @@ export interface CreateCodeContextOpts { | 'java' | 'bash' | (string & {}) + /* eslint-enable @typescript-eslint/ban-types */ /** * Timeout for the request in **milliseconds**. * @@ -157,7 +158,7 @@ export class Sandbox extends BaseSandbox { * * If not defined, the default Python context is used. */ - // eslint-disable-next-line @typescript-eslint/ban-types + /* eslint-disable @typescript-eslint/ban-types */ language?: | 'python' | 'javascript' @@ -166,6 +167,7 @@ export class Sandbox extends BaseSandbox { | 'java' | 'bash' | (string & {}) + /* eslint-enable @typescript-eslint/ban-types */ } ): Promise /** From bf3e25b13b3bb49a0e28b6752eabb83b70da5c5d Mon Sep 17 00:00:00 2001 From: Mish Ushakov <10400064+mishushakov@users.noreply.github.com> Date: Mon, 13 Apr 2026 19:38:55 +0200 Subject: [PATCH 7/7] Format Python language type annotations for ruff Co-Authored-By: Claude Opus 4.6 --- .../e2b_code_interpreter/code_interpreter_async.py | 12 ++++++++++-- python/e2b_code_interpreter/code_interpreter_sync.py | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/python/e2b_code_interpreter/code_interpreter_async.py b/python/e2b_code_interpreter/code_interpreter_async.py index e9788bc8..68001c19 100644 --- a/python/e2b_code_interpreter/code_interpreter_async.py +++ b/python/e2b_code_interpreter/code_interpreter_async.py @@ -68,7 +68,11 @@ def _client(self) -> AsyncClient: async def run_code( self, code: str, - language: Union[Literal["python", "javascript", "typescript", "r", "java", "bash"], str, None] = None, + language: Union[ + Literal["python", "javascript", "typescript", "r", "java", "bash"], + str, + None, + ] = None, on_stdout: Optional[OutputHandlerWithAsync[OutputMessage]] = None, on_stderr: Optional[OutputHandlerWithAsync[OutputMessage]] = None, on_result: Optional[OutputHandlerWithAsync[Result]] = None, @@ -202,7 +206,11 @@ async def run_code( async def create_code_context( self, cwd: Optional[str] = None, - language: Union[Literal["python", "javascript", "typescript", "r", "java", "bash"], str, None] = None, + language: Union[ + Literal["python", "javascript", "typescript", "r", "java", "bash"], + str, + None, + ] = None, request_timeout: Optional[float] = None, ) -> Context: """ diff --git a/python/e2b_code_interpreter/code_interpreter_sync.py b/python/e2b_code_interpreter/code_interpreter_sync.py index 5e3e4422..8e6eb743 100644 --- a/python/e2b_code_interpreter/code_interpreter_sync.py +++ b/python/e2b_code_interpreter/code_interpreter_sync.py @@ -65,7 +65,11 @@ def _client(self) -> Client: def run_code( self, code: str, - language: Union[Literal["python", "javascript", "typescript", "r", "java", "bash"], str, None] = None, + language: Union[ + Literal["python", "javascript", "typescript", "r", "java", "bash"], + str, + None, + ] = None, on_stdout: Optional[OutputHandler[OutputMessage]] = None, on_stderr: Optional[OutputHandler[OutputMessage]] = None, on_result: Optional[OutputHandler[Result]] = None, @@ -198,7 +202,11 @@ def run_code( def create_code_context( self, cwd: Optional[str] = None, - language: Union[Literal["python", "javascript", "typescript", "r", "java", "bash"], str, None] = None, + language: Union[ + Literal["python", "javascript", "typescript", "r", "java", "bash"], + str, + None, + ] = None, request_timeout: Optional[float] = None, ) -> Context: """