Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/add-language-overloads.md
Original file line number Diff line number Diff line change
@@ -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
45 changes: 20 additions & 25 deletions js/src/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,16 @@ export interface CreateCodeContextOpts {
*
* @default python
*/
language?: string
/* eslint-disable @typescript-eslint/ban-types */
language?:
| 'python'
| 'javascript'
| 'typescript'
| 'r'
| 'java'
| 'bash'
| (string & {})
/* eslint-enable @typescript-eslint/ban-types */
/**
* Timeout for the request in **milliseconds**.
*
Expand Down Expand Up @@ -128,29 +137,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<Execution>
/**
* Run the code for the specified language.
*
Expand All @@ -172,7 +158,16 @@ export class Sandbox extends BaseSandbox {
*
* If not defined, the default Python context is used.
*/
language?: string
/* eslint-disable @typescript-eslint/ban-types */
language?:
| 'python'
| 'javascript'
| 'typescript'
| 'r'
| 'java'
| 'bash'
| (string & {})
/* eslint-enable @typescript-eslint/ban-types */
}
): Promise<Execution>
/**
Expand Down
46 changes: 10 additions & 36 deletions python/e2b_code_interpreter/code_interpreter_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,41 +68,11 @@ 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,
Expand Down Expand Up @@ -236,7 +206,11 @@ 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:
"""
Expand Down
46 changes: 10 additions & 36 deletions python/e2b_code_interpreter/code_interpreter_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,41 +65,11 @@ 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,
Expand Down Expand Up @@ -232,7 +202,11 @@ 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:
"""
Expand Down
Loading