CKTIS / HTML
sandbox — iframe security restrictions
The sandbox attribute imposes additional restrictions on iframe content. An empty value enables the full restriction set, while allow-* tokens lift selected restrictions. Combining allow-scripts with allow-same-origin requires particular care.
Version: WHATWG HTML Living Standard; index snapshot date recorded separately
Syntax
<iframe sandbox="[space-separated permission tokens]" src="…"></iframe>sandbox is an iframe attribute that restricts the embedded document's capabilities. Omitting the attribute imposes none of these additional restrictions; sandbox="" or bare sandbox enables them all. It is not a boolean attribute: its value is an unordered set of unique, space-separated tokens, matched ASCII case-insensitively.
By default, restrictions block scripts, form submission, popups, and some navigation, among other capabilities. The document receives a unique opaque origin. allow-scripts lifts the script restriction, allow-forms lifts the form restriction, and allow-same-origin preserves the document's real origin; it does not give it the parent's origin. Tokens lift sandbox restrictions but do not bypass other browser security controls.
For content sharing the parent's origin, do not combine allow-scripts with allow-same-origin: the document can remove sandbox from its frame element and reload itself to escape the sandbox. Serve potentially hostile content from a separate, dedicated domain: opening its URL directly bypasses the frame's protection.
Changing or removing the attribute does not change the restrictions of an already-loaded document; new settings take effect on navigation. A nested frame cannot lift restrictions inherited from ancestors. sandbox does not replace the allow attribute, which controls Permissions Policy.
Examples
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Sandbox demo</title>
<iframe title="Sandboxed content" sandbox=""
srcdoc="<!doctype html><html lang='en'><meta charset='utf-8'><title>Content</title><p id='status'>Scripts blocked</p><script>document.getElementById('status').textContent = 'Scripts ran';</script></html>">
</iframe>
</html>Result
Scripts blocked
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.