0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…
Locks down an iframe: scripts, forms, popups, top-level navigation and the frame's real origin are all withheld until you add tokens to grant them back.
Overview
The sandboxattribute on <iframe> applies a set of restrictions to the framed document. With no value, everything is restricted: no scripts, no form submission, no popups, no modal dialogs, no navigating the top-level page, no downloads, and the document gets a unique opaque origin, so it is cross-origin with every other page, including the one it came from. Each token you add grants one capability back.
The demo puts the same inline document in three frames. With no tokens its script never runs. With allow-scripts it runs in an opaque origin (null) and cannot touch the page. With allow-scripts allow-same-origin it runs with this page's origin and can read and change this page.
Values
The value is an unordered, space-separated set of tokens. An empty value (sandbox or sandbox="") applies every restriction. Unknown tokens are ignored. The attribute is not inherited, but a sandboxed document's own frames and popups are sandboxed at least as strictly.
Token
Grants
allow-scripts
Running scripts (not popups: those need allow-popups).
allow-same-origin
Keep the document's real origin instead of an opaque one, so cookies, storage and same-origin APIs work. It never makes third-party content same-origin with your page.
allow-forms
Submitting forms.
allow-modals
alert(), confirm(), prompt() and print().
allow-popups
Opening new windows (window.open(), target="_blank"). The popup inherits the sandbox.
allow-popups-to-escape-sandbox
Popups open without the sandbox (needed for "open this post on the site" links).
allow-top-navigation-by-user-activation
Navigating the top-level page, but only from a click or other user gesture.
allow-top-navigation
Navigating the top-level page at any time, with or without a gesture.
allow-top-navigation-to-custom-protocols
Navigating to non-HTTP schemes such as mailto:. Not implemented in Chromium.
allow-downloads
Starting downloads.
allow-pointer-lock
The Pointer Lock API.
allow-orientation-lock
Locking screen orientation.
allow-presentation
The Presentation API.
allow-storage-access-by-user-activation
Requesting unpartitioned cookie access through the Storage Access API. Not yet in the HTML standard.
A sandboxed frame can always navigate itself; the sandbox restricts navigating other frames and the top-level page.
Examples
Untrusted third-party widget
Start from an empty sandbox and add only what the embed needs. A third-party URL is a different origin, so allow-same-origin just lets it keep its own cookies; it still cannot reach your page.
Least privilege
123456789
<!-- Static content: everything restricted --><iframesrc="https://widgets.example.net/badge"sandboxtitle="Status badge"></iframe><!-- A survey that needs scripts and form submission, nothing else --><iframesrc="https://forms.example.net/survey/42"sandbox="allow-scripts allow-forms"title="Customer survey"></iframe>
Checkout that may redirect the page
Payment flows sometimes need to send the whole page to a 3-D Secure or confirmation step. Grant top-level navigation only from a user gesture, so the frame cannot redirect your page on its own (a common phishing trick).
For HTML you hold as a string (previews, emails, user posts) use srcdoc with an empty sandbox. Without a sandbox, srcdoc content runs with your origin.
Sandboxed srcdoc
123
<iframesandboxsrcdoc="<h2>Re: Thursday</h2><p>Sounds good, see you then.</p>"title="Message preview"></iframe>
The escape: same-origin content with scripts
This is the configuration the demo's third frame shows. The content is same-origin with the page (a path on your own site, a srcdoc document or about:blank), and the sandbox lets it keep that origin and run scripts. It can reach into the parent, including frameElement, and remove its own sandboxattribute.
Unsafe: do not do this for content you do not control
123456789
<!-- UNSAFE: same-origin content + allow-scripts + allow-same-origin --><iframesrc="/uploads/user-page.html"sandbox="allow-scripts allow-same-origin"title="User page"></iframe><!-- UNSAFE for the same reason: srcdoc inherits this page's origin --><iframesrcdoc="..."sandbox="allow-scripts allow-same-origin"title="Preview"></iframe>
For cross-origin content (a different host) the same two tokens are fine: the browser's same-origin policy still separates the frame from your page. Browsers warn in the console whenever both tokens appear, whatever the origin.
In Vanilla Breeze
<social-embed> renders every post (Bluesky, Mastodon, X, Instagram) as a sandboxed, lazily loaded iframe with referrerpolicy="strict-origin". Built-in providers use allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox, which is safe because the frames are on the provider's origin; Mastodon drops allow-popups-to-escape-sandbox. See src/web-components/social-embed/shared.js (createEmbedFrame, POST_SANDBOX).
VB's HTML sanitiser (src/lib/sanitize-html.js), used for untrusted markdown and comments, removes <iframe> elements and the srcdocattribute entirely rather than trying to sandbox them.
Styling: iframe.bordered, iframe.rounded and iframe[data-ratio="16:9"] come from src/native-elements/iframe/styles.css; the attribute itself has no styling hook.
Doc-site demos in <browser-window> are not sandboxed: they are same-origin VB pages.
Accessibility
Give every iframe a title that names its content; screen readers announce it on entry.
Sandboxing does not change focus order: keyboard users tab into and out of the frame as usual. Test that the embedded content itself is keyboard-usable, because blocked scripts can leave half-working controls.
When a feature is blocked (forms, popups), the user gets no feedback inside the frame. If an embed depends on one, grant it or link to the content directly.
Security
Never combine allow-scripts and allow-same-origin for same-origin content you do not control, including srcdoc and about:blank. The sandbox becomes advisory.
Prefer allow-top-navigation-by-user-activation over allow-top-navigation.
allow-popups-to-escape-sandbox means links in the frame open unrestricted pages. Use it only for trusted providers.
Changes to the sandboxattribute apply on the frame's next navigation, not to the document already loaded.
Sandbox limits what the frame can do; Content Security Policy limits what it can load. Pages you serve yourself can also be sandboxed with the Content-Security-Policy: sandbox header.
Browser support
The attribute and the core tokens are supported everywhere. As of November 2026 (MDN browser-compat-data): allow-downloads Chrome 83, Firefox 82, Safari 17; allow-top-navigation-to-custom-protocols Firefox 101 and Safari 16, not Chromium; allow-storage-access-by-user-activation Chrome 113, Firefox 65, Safari 11.1.
Gotchas
Blocked actions are quiet in the page but logged in the console. Chromium logs, for example, "Blocked form submission … because the form's frame is sandboxed and the 'allow-forms' permission is not set." Check DevTools when an embed seems broken.
Opaque origin side effects. Without allow-same-origin, localStorage and cookie access throw or are empty, origin is "null", and CORS requests carry Origin: null.
Popups inherit the sandbox unless you add allow-popups-to-escape-sandbox, which can break sites opened from the frame.
allow-scripts is all or nothing. Use CSP inside the framed document for finer control.
Related
srcdoc — inline HTML in a frame; needs sandbox when the HTML is untrusted.
allow — Permissions Policy: camera, fullscreen, payment and other powerful APIs.
referrerpolicy — how much of your URL the frame's request reveals.
target — _top and _parent navigation, which the sandbox restricts.
nonce — Content Security Policy for your own scripts.