Skip to content

fix(sandbox): replace forEach(async) with Promise.all to prevent race condition on multi-file writes#232

Open
Prasad48432 wants to merge 1 commit into
e2b-dev:mainfrom
Prasad48432:fix/await-sandbox-file-writes
Open

fix(sandbox): replace forEach(async) with Promise.all to prevent race condition on multi-file writes#232
Prasad48432 wants to merge 1 commit into
e2b-dev:mainfrom
Prasad48432:fix/await-sandbox-file-writes

Conversation

@Prasad48432

Copy link
Copy Markdown

Summary

Fixes #229.

Resolves a race condition in the sandbox API route where sbx.runCode() could
be invoked before all sandbox file writes had completed, causing code execution
against a partially-written filesystem for multi-file fragments.


Root Cause

In app/api/sandbox/route.ts, the multi-file write path used:

fragment.code.forEach(async (file) => {
  await sbx.files.write(file.file_path, file.file_content)
  console.log(`Copied file to ${file.file_path} in ${sbx.sandboxId}`)
})

@cla-bot

cla-bot Bot commented Jul 12, 2026

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement, and we don't have @Prasad48432 on file. You can sign our CLA at https://e2b.dev/docs/cla . Once you've signed, post a comment here that says '@cla-bot check'

@vercel

vercel Bot commented Jul 12, 2026

Copy link
Copy Markdown

@Prasad48432 is attempting to deploy a commit to the E2B Team on Vercel.

A member of the Team first needs to authorize it.

@mishushakov mishushakov requested review from OndrejDrapalik and removed request for ben-fornefeld and mlejva July 13, 2026 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sandbox route: forEach(async) fire-and-forget can run code before multi-file writes finish

1 participant