Add language autocomplete for supported languages#247
Add language autocomplete for supported languages#247mishushakov wants to merge 8 commits intomainfrom
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
PR SummaryLow Risk Overview In TypeScript, replaces free-form Reviewed by Cursor Bugbot for commit d1bdaed. Bugbot is set up for automated code reviews on this repo. Configure here. |
There was a problem hiding this comment.
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_codeinto two language overloads—Optional[Literal[...]]for known languages andOptional[str]for arbitrary strings—so Pyright no longer collapses literals intostrand IDEs can suggest the known language strings again.
- Split
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.
There was a problem hiding this comment.
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].
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>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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.


Summary
javascript,typescript,r,java, andbashlanguages inrunCode/run_codeandcreateCodeContext/create_code_contextLiteral["python"]overload and the genericstroverload into a single overload with a union of known language literals(string & {})trick in TypeScript to preserve autocomplete while still accepting arbitrary stringsTest plan
🤖 Generated with Claude Code