{"record":{"id":"577ed8a27c315a7a","repo":"firecrawl/open-lovable","slug":"no-active-sandbox","errorCode":null,"errorMessage":"No active sandbox","messagePattern":"No active sandbox","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/sandbox/providers/e2b-provider.ts","lineNumber":75,"sourceCode":"        createdAt: new Date()\n      };\n\n      // Set extended timeout on the sandbox instance if method available\n      if (typeof this.sandbox.setTimeout === 'function') {\n        this.sandbox.setTimeout(appConfig.e2b.timeoutMs);\n      }\n\n      return this.sandboxInfo;\n\n    } catch (error) {\n      console.error('[E2BProvider] Error creating sandbox:', error);\n      throw error;\n    }\n  }\n\n  async runCommand(command: string): Promise<CommandResult> {\n    if (!this.sandbox) {\n      throw new Error('No active sandbox');\n    }\n\n    \n    const result = await this.sandbox.runCode(`\n      import subprocess\n      import os\n\n      os.chdir('/home/user/app')\n      result = subprocess.run(${JSON.stringify(command.split(' '))}, \n                            capture_output=True, \n                            text=True, \n                            shell=False)\n\n      print(\"STDOUT:\")\n      print(result.stdout)\n      if result.stderr:\n          print(\"\\\\nSTDERR:\")\n          print(result.stderr)","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/firecrawl/open-lovable/blob/69bd93bae7a9c97ef989eb70aabe6797fb3dac89/lib/sandbox/providers/e2b-provider.ts#L57-L93","documentation":"E2BProvider throws 'No active sandbox' when a lifecycle method (runCommand) is called before a sandbox instance exists. this.sandbox is only assigned by createSandbox() (or reconnect()); every operation guards on it and fails fast. It signals a programming-order mistake, not a sandbox runtime failure.","triggerScenarios":"Calling provider.runCommand(cmd) without first awaiting provider.createSandbox(); using a freshly constructed E2BProvider; calling after a sandbox expired/crashed and this.sandbox was reset without recreation.","commonSituations":"Instantiating the provider in a route handler and calling runCommand immediately; sandbox idled out mid-session (E2B timeouts) so the reference is stale/null; race where two requests share one provider and one closed it; forgetting createSandbox() after a refactor.","solutions":["Call `await provider.createSandbox()` before any runCommand/writeFile/readFile/listFiles/installPackages/setupViteApp/restartViteServer call","Check `if (!provider.hasActiveSandbox?.()) await provider.createSandbox()` at the start of each request","If the sandbox expired, reconnect via `await provider.reconnect(sandboxId)` or recreate it","Wrap provider usage in a lazy-init helper that creates the sandbox once and reuses it"],"exampleFix":"// before\nconst provider = new E2BProvider();\nawait provider.runCommand('ls');\n// after\nconst provider = new E2BProvider();\nawait provider.createSandbox();\nawait provider.runCommand('ls');","handlingStrategy":"validation","validationCode":"if (!provider.sandbox) {\n  await provider.createSandbox();\n}\nawait provider.runCommand(command);","typeGuard":"function hasActiveSandbox(p): p is E2BProvider & { sandbox: NonNullable<E2BProvider['sandbox']> } {\n  return p.sandbox != null;\n}","tryCatchPattern":"try {\n  await provider.runCommand(cmd);\n} catch (e) {\n  if (e instanceof Error && e.message === 'No active sandbox') {\n    await provider.createSandbox();\n    return provider.runCommand(cmd);\n  }\n  throw e;\n}","preventionTips":["Always await createSandbox() immediately after constructing the provider","Wrap provider operations in an ensureSandbox() helper","Track E2B sandbox TTL and refresh before expiry","Never swallow createSandbox() errors — a failed create leaves null state","Use one provider instance per sandbox lifetime"],"tags":["sandbox","lifecycle","e2b"],"backgroundTag":"no-active-sandbox","analyzedSha":"69bd93bae7a9c97ef989eb70aabe6797fb3dac89","analyzedAt":"2026-08-28T22:20:32.339Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}