e2b-dev / e2b-dev/fragments

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

Open Beginner friendly
#229 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
6.4k
Forks
862
Avg merge
2d 22h
Merged PRs (30d)
2

Description

Problem

Multi-file fragments can execute before all files are written to the sandbox — a race condition in app/api/sandbox/route.ts.

Location

app/api/sandbox/route.ts:52-56:

if (fragment.code && Array.isArray(fragment.code)) {
  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}`)
  })
}

Array.prototype.forEach ignores the promises returned by the async callback. The outer POST handler continues to sbx.runCode(...) / URL return at line 62+ without awaiting the writes.

Steps

  1. Generate a multi-file fragment (Next.js/Vue template producing 2+ files).
  2. POST to /api/sandbox with fragment.code as an array.
  3. Sandbox may run/serve before later files are on disk.

Expected

All files persisted before execution/URL return.

Actual

Fire-and-forget writes; ordering depends on E2B SDK internal timing.

Fix

Replace with await Promise.all(fragment.code.map(file => sbx.files.write(...))).

Environment

@e2b/code-interpreter@^1.0.2, next@^14.2.35, Node per repo package.json.

Thanks for maintaining e2b-dev/fragments!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in app/api/sandbox/route.ts:52-56 and trace the POST handler through sbx.runCode and the URL return. Reproduce with a multi-file fragment, then verify that every file is persisted before execution or the URL is returned.

Written by the indexing model from the issue text.

Assessment

Tech stack
nextjs, typescript
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
82/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.