mozilla/pdf.js · error · Error
Cannot start sandbox
Error message
Cannot start sandbox
What it means
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.
Source
Thrown at src/pdf.sandbox.js:98
[buf, this._alertOnError]
);
} catch (error) {
// eslint-disable-next-line no-console
console.error(error);
} finally {
if (buf) {
this._module.ccall("free", "number", ["number"], [buf]);
}
}
if (success) {
this.support.commFun = this._module.cwrap("commFun", null, [
"string",
"string",
]);
} else {
this.nukeSandbox();
throw new Error("Cannot start sandbox");
}
}
dispatchEvent(event) {
this.support?.callSandboxFunction("dispatchEvent", event);
}
dumpMemoryUse() {
this._module?.ccall("dumpMemoryUse", null, []);
}
nukeSandbox() {
if (this._module !== null) {
this.support.destroy();
this.support = null;
this._module.ccall("nukeSandbox", null, []);
this._module = null;
}View on GitHub (pinned to 5903d58d58)
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.
Defensive patterns
Strategy: try-catch
Validate before calling
// Ensure the sandbox asset is reachable and CSP allows WASM before enabling scripting. // headers: Content-Security-Policy: script-src 'self' 'wasm-unsafe-eval';
Type guard
function runtimeSupportsWasm() {
return typeof WebAssembly === 'object' && typeof WebAssembly.compile === 'function';
} Try / catch
try {
await pdfjsSandboxInit();
} catch (e) {
if (e.message === 'Cannot start sandbox') {
// disable interactive form scripting; forms still display
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Cannot create sandbox.
- The PDF file is empty, i.e. its size is zero bytes.
- No ICC color space support
- JBig2 failed to initialize
- OpenJPEG failed to initialize
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/f304c10759a6092c.
Report an issue: GitHub.