Skip to content

Add language autocomplete for supported languages#247

Open
mishushakov wants to merge 8 commits intomainfrom
mishushakov/add-language-overloads
Open

Add language autocomplete for supported languages#247
mishushakov wants to merge 8 commits intomainfrom
mishushakov/add-language-overloads

Conversation

@mishushakov
Copy link
Copy Markdown
Member

@mishushakov mishushakov commented Apr 13, 2026

Summary

  • Add autocomplete/type hints for javascript, typescript, r, java, and bash languages in runCode/run_code and createCodeContext/create_code_context
  • Consolidate the Python-specific Literal["python"] overload and the generic str overload into a single overload with a union of known language literals
  • Use (string & {}) trick in TypeScript to preserve autocomplete while still accepting arbitrary strings

Test plan

  • Verify IDE autocomplete suggests all six languages in TypeScript
  • Verify IDE autocomplete suggests all six languages in Python

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cursor
Copy link
Copy Markdown

cursor bot commented Apr 13, 2026

PR Summary

Low Risk
Type-hint/overload-only changes to JS/TS and Python SDKs; runtime behavior is unchanged, with minimal risk beyond potential typing edge cases in IDEs/type checkers.

Overview
Adds editor autocomplete/type hints for supported languages (python, javascript, typescript, r, java, bash) when calling runCode/run_code and createCodeContext/create_code_context.

In TypeScript, replaces free-form string language types with a literal-union plus (string & {}) to keep autocomplete while still accepting arbitrary strings. In Python, consolidates the previous Python-specific vs generic overloads into a single overload that unions known Literal[...] languages with str.

Reviewed by Cursor Bugbot for commit d1bdaed. Bugbot is set up for automated code reviews on this repo. Configure here.

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Python Literal union with str defeats autocomplete purpose
    • Split run_code into two language overloads—Optional[Literal[...]] for known languages and Optional[str] for arbitrary strings—so Pyright no longer collapses literals into str and IDEs can suggest the known language strings again.

Create PR

Or push these changes by commenting:

@cursor push 05e34a1f0a
Preview (05e34a1f0a)
diff --git a/python/e2b_code_interpreter/code_interpreter_async.py b/python/e2b_code_interpreter/code_interpreter_async.py
--- a/python/e2b_code_interpreter/code_interpreter_async.py
+++ b/python/e2b_code_interpreter/code_interpreter_async.py
@@ -68,7 +68,9 @@
     async def run_code(
         self,
         code: str,
-        language: Union[Literal["python", "javascript", "typescript", "r", "java", "bash"], str, None] = None,
+        language: Optional[
+            Literal["python", "javascript", "typescript", "r", "java", "bash"]
+        ] = None,
         on_stdout: Optional[OutputHandlerWithAsync[OutputMessage]] = None,
         on_stderr: Optional[OutputHandlerWithAsync[OutputMessage]] = None,
         on_result: Optional[OutputHandlerWithAsync[Result]] = None,
@@ -103,6 +105,41 @@
     async def run_code(
         self,
         code: str,
+        language: Optional[str] = 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 for the specified language.
+
+        Specify the `language` or `context` option to run the code as a different language or in a different `Context`.
+        If no language is specified, Python is used.
+
+        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,
         context: Optional[Context] = None,
         on_stdout: Optional[OutputHandlerWithAsync[OutputMessage]] = None,
         on_stderr: Optional[OutputHandlerWithAsync[OutputMessage]] = None,

diff --git a/python/e2b_code_interpreter/code_interpreter_sync.py b/python/e2b_code_interpreter/code_interpreter_sync.py
--- a/python/e2b_code_interpreter/code_interpreter_sync.py
+++ b/python/e2b_code_interpreter/code_interpreter_sync.py
@@ -65,7 +65,9 @@
     def run_code(
         self,
         code: str,
-        language: Union[Literal["python", "javascript", "typescript", "r", "java", "bash"], str, None] = None,
+        language: Optional[
+            Literal["python", "javascript", "typescript", "r", "java", "bash"]
+        ] = None,
         on_stdout: Optional[OutputHandler[OutputMessage]] = None,
         on_stderr: Optional[OutputHandler[OutputMessage]] = None,
         on_result: Optional[OutputHandler[Result]] = None,
@@ -100,6 +102,41 @@
     def run_code(
         self,
         code: str,
+        language: Optional[str] = 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 for the specified language.
+
+        Specify the `language` or `context` option to run the code as a different language or in a different `Context`.
+        If no language is specified, Python is used.
+
+        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,
         context: Optional[Context] = None,
         on_stdout: Optional[OutputHandler[OutputMessage]] = None,
         on_stderr: Optional[OutputHandler[OutputMessage]] = None,

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — pure type hint improvement with no runtime changes.

Extended reasoning...

Overview

This PR touches four files: a changeset, the TypeScript sandbox, and both the async and sync Python sandboxes. All changes are limited to type signatures — adding language literal unions for autocomplete and removing redundant overloads.

Security Risks

None. No execution logic, authentication, or data handling is modified.

Level of Scrutiny

Low. The changes are mechanical: swapping string / Optional[str] for union literals in public API signatures. The (string & {}) TypeScript trick is a well-known pattern for preserving literal autocomplete while still accepting arbitrary strings, and the Python consolidation from two overloads to one is equivalent in behavior.

Other Factors

No bugs were reported by the bug hunting system. The cursor[bot] summary also rates this low risk. Runtime behavior is identical — the implementation methods continue to accept Optional[str].

mishushakov and others added 6 commits April 13, 2026 19:29
Use NonNullable<unknown> instead of {} to satisfy @typescript-eslint/ban-types.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit bf3e25b. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant