You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Document JavaScript top-level await feature that allows developers to
write async code without IIFE wrappers. Include examples of automatic
expression return behavior and state persistence across executions.
Related PR: cloudflare/sandbox-sdk#261
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: src/content/docs/sandbox/api/interpreter.mdx
+55-1Lines changed: 55 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,45 @@ import { TypeScriptExample } from "~/components";
9
9
10
10
Execute Python, JavaScript, and TypeScript code with support for data visualizations, tables, and rich output formats. Contexts maintain state (variables, imports, functions) across executions.
11
11
12
-
JavaScript contexts support top-level `await` - no need to wrap async code in IIFE. The last expression is automatically returned as the result.
12
+
## JavaScript top-level await support
13
+
14
+
JavaScript execution supports top-level `await` without requiring an async IIFE wrapper. The code interpreter automatically transforms your code to enable async operations and returns the value of the last expression.
15
+
16
+
<TypeScriptExample>
17
+
```
18
+
// No wrapper needed - just write async code directly
@@ -113,6 +151,8 @@ console.log(result.results[0]); // Last expression is automatically returned
113
151
:::note[Default context behavior]
114
152
If no `context` is provided, a default context is automatically created/reused for the specified `language`. While convenient for quick tests, **explicitly creating contexts is recommended** for production use to maintain predictable state.
0 commit comments