different-ai/openwork · warning
MCP_APP_SANDBOX_DOCUMENT_ERROR
MCP_APP_SANDBOX_DOCUMENT_ERROR
Error message
The sandbox iframe reported a document load error.
What it means
The MCP app sandbox iframe fired its native `error` event after an HTML resource had already been assigned (resourceAssigned === true). The sandbox notifies the host via a sandbox-diagnostic with code MCP_APP_SANDBOX_DOCUMENT_ERROR, meaning the srcdoc document failed at load time (e.g. blocked script, CSP violation, malformed HTML triggering a resource error).
Source
Thrown at apps/server/src/mcp-app-sandbox.ts:98
const inner = document.createElement("iframe");
inner.title = "MCP App view";
inner.style.cssText = "display:block;width:100%;height:100%;border:0;background:transparent";
inner.setAttribute("sandbox", "allow-scripts allow-same-origin");
let resourceAssigned = false;
inner.addEventListener("load", () => {
if (!resourceAssigned) return;
let readyState = null;
let hasHtmlRoot = null;
let scriptCount = null;
try {
readyState = inner.contentDocument?.readyState || null;
hasHtmlRoot = Boolean(inner.contentDocument?.documentElement);
scriptCount = inner.contentDocument?.scripts.length ?? null;
} catch {}
notifyHost("ui/notifications/sandbox-resource-loaded", { readyState, hasHtmlRoot, scriptCount });
});
inner.addEventListener("error", () => {
if (resourceAssigned) notifyHost("ui/notifications/sandbox-diagnostic", { code: "MCP_APP_SANDBOX_DOCUMENT_ERROR", message: "The sandbox iframe reported a document load error." });
});
document.body.appendChild(inner);
window.addEventListener("message", (event) => {
if (event.source === window.parent) {
if (event.origin !== hostOrigin) return;
if (event.data?.method === "ui/notifications/sandbox-resource-ready") {
const html = event.data?.params?.html;
const sandbox = event.data?.params?.sandbox;
if (typeof sandbox === "string" && /^(?:allow-scripts|allow-same-origin|\s)+$/.test(sandbox)) inner.setAttribute("sandbox", sandbox);
if (typeof html !== "string") {
notifyHost("ui/notifications/sandbox-diagnostic", { code: "MCP_APP_SANDBOX_RESOURCE_INVALID", message: "The sandbox received an invalid HTML resource payload." });
return;
}
try {
resourceAssigned = true;
inner.srcdoc = html;
notifyHost("ui/notifications/sandbox-resource-accepted");
} catch {View on GitHub (pinned to 2b7df46e8a)
Solutions
- Check the sandbox attribute includes allow-scripts when the app HTML executes JavaScript.
- Open the iframe/webview devtools console for the underlying CSP or script error details.
- Remove or inline external resource references that violate the sandbox's opaque origin.
- If the error is benign (e.g. favicon 404 surfacing as an error), filter it in the host's sandbox-diagnostic handler.
Example fix
// before
inner.setAttribute("sandbox", "allow-same-origin");
// after
inner.setAttribute("sandbox", "allow-scripts allow-same-origin"); Defensive patterns
Strategy: validation
Validate before calling
const needsScripts = /<script/i.test(appHtml);
const sandboxAttr = inner.getAttribute("sandbox") ?? "";
if (needsScripts && !sandboxAttr.includes("allow-scripts")) {
inner.setAttribute("sandbox", (sandboxAttr + " allow-scripts").trim());
} Try / catch
window.addEventListener("message", (e) => {
if (e.data?.code === "MCP_APP_SANDBOX_DOCUMENT_ERROR") {
console.warn("sandbox doc load error — check iframe console/CSP");
}
}); Prevention
- Match the sandbox attribute to the app's needs (allow-scripts for JS apps)
- Test app HTML inside a sandboxed iframe in CI, not only top-level
- Keep inline scripts/resources self-contained for the opaque origin
When it happens
Trigger: Setting inner.srcdoc to HTML whose load raises an iframe error event — scripts blocked by the sandbox attribute, CSP refusing inline scripts, or the document referencing resources that fail hard enough to error the frame.
Common situations: Sandbox attr lacking allow-scripts while the HTML includes <script>; server CSP (frame-src/CSP headers) conflicting with srcdoc; app HTML expecting same-origin assets unavailable in the sandboxed origin.
Related errors
- MCP_APP_SANDBOX_RESOURCE_INVALID
- MCP_APP_SANDBOX_RESOURCE_ASSIGNMENT_FAILED
- invalid_resource_csp
- invalid_resource_uri
- unsupported_resource_permissions
AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01).
Data as JSON: /api/errors/26ff53c9e7826150.
Report an issue: GitHub.