Skip to content

Async Code Not Executing Correctly in e2b Sandbox Environment #477

@abubakar7033

Description

@abubakar7033

When executing JavaScript code containing asynchronous operations (e.g., async/await), the e2b Sandbox environment fails to execute the code as expected. Instead of resolving the asynchronous functions, the sandbox returns a Promise { } as a string or encounters a syntax error with await not being allowed outside async functions.

Steps to Reproduce:

Create an async function in the code to perform asynchronous tasks (e.g., fetch requests, setTimeout, etc.).
Use await to resolve the promise within the async function.
Execute the code in the e2b Sandbox environment using the runCode method.
Expected Behavior: The async function should run as expected, resolving the promise and providing the output. The asynchronous operations should be awaited, and their results should be returned correctly.

Actual Behavior:

The output is returned as Promise { } instead of the resolved result.
In some cases, a SyntaxError is thrown indicating that await is only valid in async functions or top-level modules.

Example Code:

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions