{"record":{"id":"f304c10759a6092c","repo":"mozilla/pdf.js","slug":"cannot-start-sandbox","errorCode":null,"errorMessage":"Cannot start sandbox","messagePattern":"Cannot start sandbox","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/pdf.sandbox.js","lineNumber":98,"sourceCode":"        [buf, this._alertOnError]\n      );\n    } catch (error) {\n      // eslint-disable-next-line no-console\n      console.error(error);\n    } finally {\n      if (buf) {\n        this._module.ccall(\"free\", \"number\", [\"number\"], [buf]);\n      }\n    }\n\n    if (success) {\n      this.support.commFun = this._module.cwrap(\"commFun\", null, [\n        \"string\",\n        \"string\",\n      ]);\n    } else {\n      this.nukeSandbox();\n      throw new Error(\"Cannot start sandbox\");\n    }\n  }\n\n  dispatchEvent(event) {\n    this.support?.callSandboxFunction(\"dispatchEvent\", event);\n  }\n\n  dumpMemoryUse() {\n    this._module?.ccall(\"dumpMemoryUse\", null, []);\n  }\n\n  nukeSandbox() {\n    if (this._module !== null) {\n      this.support.destroy();\n      this.support = null;\n      this._module.ccall(\"nukeSandbox\", null, []);\n      this._module = null;\n    }","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/pdf.sandbox.js#L80-L116","documentation":"Thrown by the QuickJS sandbox bootstrap when the WASM module failed to initialize (the internal `success` flag is false). The sandbox is required to execute interactive PDF form JavaScript safely, so a failed start nukes the sandbox and aborts scripting support. It is an environment/loading failure, not a PDF-content failure.","triggerScenarios":"The sandbox setup routine runs to completion but reports failure: the WASM module did not compile/instantiate or its entry points are missing; nukeSandbox() is called then the error is thrown.","commonSituations":"Content-Security-Policy blocks WASM ('wasm-unsafe-eval' or script-src too strict); the pdf.sandbox wasm asset is missing or 404; a build version mismatch between sandbox loader and wasm; an out-of-memory or unsupported-WASM environment.","solutions":["Ensure the sandbox WASM asset is served with the correct MIME type and is reachable.","Allow WASM in CSP (add 'wasm-unsafe-eval' to script-src, or loosen worker-src).","Use matching versions of the PDF.js API and the sandbox bundle.","Verify the runtime supports WebAssembly."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Ensure the sandbox asset is reachable and CSP allows WASM before enabling scripting.\n// headers: Content-Security-Policy: script-src 'self' 'wasm-unsafe-eval';","typeGuard":"function runtimeSupportsWasm() {\n  return typeof WebAssembly === 'object' && typeof WebAssembly.compile === 'function';\n}","tryCatchPattern":"try {\n  await pdfjsSandboxInit();\n} catch (e) {\n  if (e.message === 'Cannot start sandbox') {\n    // disable interactive form scripting; forms still display\n  }\n}","preventionTips":["Allow WASM via CSP ('wasm-unsafe-eval' in script-src).","Serve the sandbox wasm asset with the correct MIME type.","Keep the sandbox bundle and API bundle on the same version.","Detect WebAssembly support before enabling scripting features."],"tags":["sandbox","wasm","scripting","csp","loading"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}