Skip to content

Conversation

@agents-git-bot
Copy link
Contributor

@agents-git-bot agents-git-bot bot commented Nov 28, 2025

Summary

Documents the new top-level await support for JavaScript code execution in the Sandbox SDK. This feature allows developers to write async JavaScript code without manually wrapping it in async IIFE functions.

Changes

interpreter.mdx

  • Added comprehensive "JavaScript top-level await support" section with practical examples
  • Documented key features: no IIFE wrapper, automatic return of last expression, state persistence
  • Added multiple code examples showing top-level await in various contexts
  • Enhanced examples in default context behavior section

code-execution.mdx

  • Added top-level await documentation in code execution guide
  • Included examples showing direct async/await usage patterns
  • Documented automatic code transformation behavior

Key Features Documented

Automatic code transformation:

  • JavaScript code is automatically wrapped to enable top-level await
  • Last expression value is returned when it's a standalone expression
  • Promises are resolved transparently

Developer experience improvements:

// Before - manual IIFE wrapping required
(async () => {
  const data = await fetch('...');
  return data;
})()

// After - direct top-level await
const data = await fetch('...');
data

Related

🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

Adds documentation for the new top-level await feature in JavaScript
code interpreter contexts. This enhancement allows users to write
async code without manual IIFE wrapping.

Changes:
- Add top-level await section to code-execution.mdx guide
- Update AI-generated code example to showcase async patterns
- Add JavaScript top-level await documentation to interpreter.mdx API reference
- Explain automatic async wrapping and expression return behavior

Synced from cloudflare/sandbox-sdk PR #261

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions
Copy link
Contributor

This pull request requires reviews from CODEOWNERS as it changes files that match the following patterns:

Pattern Owners
/src/content/docs/sandbox/ @whoiskatrin, @ghostwriternr, @cloudflare/pcx-technical-writing, @cloudflare/ai-agents

Add documentation for new top-level await feature in JavaScript contexts:
- No IIFE wrapper needed for async code
- Last expression automatically returned as result
- Seamless support for multiple await expressions

Updated:
- API reference (interpreter.mdx) with top-level await example
- How-to guide (code-execution.mdx) with comprehensive examples

Related to cloudflare/sandbox-sdk#261

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants