Skip to main content
All Terms Glossary

Sandbox Attribute for Iframes

Definition

The sandbox attribute is an HTML attribute for iframes that applies browser-enforced restrictions to the framed document, blocking script execution, form submission, popups, and top-level navigation until you grant each capability back with a token such as allow-scripts. That is also what an 'iframe sandbox detected' warning from a security scanner or a video player is reporting: the frame is running under sandbox restrictions.

What 'iframe sandbox detected' means

An 'iframe sandbox detected' message appears when a browser security extension, a site scanner, or an embedded video player reports that the iframe it is running inside has one or more sandbox restrictions active. These messages are informational rather than errors: they tell you that the embedding page applied the HTML sandbox attribute to the frame, which limits what the embedded content can do. Common triggers include security scanners checking for over-permissive iframes and media players (YouTube, Vimeo, Dailymotion) that need allow-scripts, and usually allow-same-origin, before they will run. Autoplay and fullscreen are not sandbox tokens at all: an iframe receives those through the separate allow attribute, which is Permissions Policy. The message is not itself a threat; it is a signal that sandbox restrictions are in effect and need to be checked against what the embed requires.

What the iframe sandbox attribute does

The sandbox attribute is a token list you add to an iframe to strip away the embedded document's default capabilities and then grant back only the ones you choose. An empty sandbox applies the maximum set of restrictions: the framed content runs in a unique opaque origin, cannot execute scripts, cannot submit forms, cannot open popups, cannot navigate the top-level page, and cannot use plugins. You loosen it selectively with flags such as allow-scripts, allow-forms, allow-same-origin, and allow-popups. Each keyword re-enables one capability, so the frame receives the least privilege the feature actually needs. It is defined in the HTML standard and enforced by the browser itself.

Why the sandbox attribute matters for security

Embedding third-party or user-supplied content without isolation lets that content script the host page, read cookies, submit forms, or hijack navigation. The sandbox attribute reduces the blast radius when embedded markup is untrusted, for example an advertisement, a rich-text preview, or a widget. A key subtlety is that combining allow-scripts with allow-same-origin defeats much of the protection: the frame can then reach into its own served origin, and if that origin matches the embedder, it can remove its own sandbox by rewriting the frame. Sandboxing is a containment control, not a content-inspection control, so it limits what compromised markup can do but does not tell you whether the markup was tampered with.

Applying the sandbox attribute safely

Grant the narrowest set of flags the embedded feature requires, and never pair allow-scripts with allow-same-origin for content you do not fully trust. Serve untrusted embeds from a separate, cookieless origin so an opaque-origin frame cannot reach real session data. Pair the attribute with a Content Security Policy and framing controls so defenses do not depend on a single flag. Sandboxing governs iframes you author; it does nothing about the behavior of the many first- and third-party scripts loading directly on your own pages. cside addresses that gap by analysing those scripts in real visitor sessions, detecting malicious behavior at runtime, and keeping a forensic record.

Definition

What does 'iframe sandbox detected' mean?

It means a browser extension, security scanner, or media player has found that the iframe it is embedded in carries the HTML sandbox attribute. The attribute limits what the frame can do: run scripts, submit forms, open popups, navigate the top-level page. The detection itself is not an attack; it is confirmation that sandboxing is in place. Whether that is the desired behavior depends on whether the embed needs the blocked capabilities to function.

Definition

Why do video players ask to remove sandbox attributes on the iframe tag?

Most video embeds (YouTube, Vimeo, Dailymotion) need allow-scripts to run their player at all, usually allow-same-origin so the player can reach its own storage, and often allow-popups for share and watch-later links. A bare sandbox with none of those tokens stops the player executing any JavaScript, so it fails silently or shows the 'sandbox detected' warning. Autoplay and fullscreen come from a different mechanism: they are delegated through the iframe's allow attribute, for example allow="autoplay; fullscreen; picture-in-picture", which is Permissions Policy rather than sandbox. The fix is to add exactly the tokens the player documents rather than dropping sandbox, because sandbox is also what stops a cross-origin player submitting forms, opening popups, or navigating your top-level page away.

Definition

Is it safe to remove sandbox attributes from an iframe?

Removing it lifts the browser-imposed restrictions on that frame: the embedded document can then execute scripts, submit forms, open popups, use plugins, and navigate your top-level page away. It does not hand a cross-origin embed access to your cookies or your DOM, because the same-origin policy already blocks that whether or not sandbox is present. The case that genuinely matters is a same-origin frame carrying allow-scripts and allow-same-origin together, since the framed document can then reach into the parent page and remove its own sandbox attribute. Keep sandbox, add only the specific tokens the embed documents, and serve untrusted embeds from a separate cookieless origin where possible.

Definition

Does the sandbox attribute replace a Content Security Policy?

No. The sandbox attribute restricts what one embedded iframe can do, while a Content Security Policy governs what the whole page may load and execute. They cover different scopes and work best together: sandbox contains an untrusted embed, and CSP restricts scripts, connections, and framing across the document.

Definition

Why is allow-scripts plus allow-same-origin considered dangerous?

Together they let the framed document run scripts with access to its real origin. If that origin is the embedder's, the frame can read the same data and even rewrite its own markup to drop the sandbox attribute, effectively escaping the restrictions you intended to impose.

Got more questions

Talk to a security expert

We answer client-side security questions every day. Bring yours.

Book a demo

Want to walk through this with an engineer?

Thirty minutes, on your own site. Not a slide deck.

Book a personalized demo to see:

How to achieve PCI DSS requirement 6.4.3 & 11.6.1 compliance in 1 day
Why third-party scripts are a security risk for you and your visitors
Monitoring privacy and consent leakage (GDPR, CCPA) across every third party
Stopping signup abuse, account sharing, and chargeback fraud with device intelligence
Detecting and controlling AI agents and bots hitting your site in real time

Rather just send a question?

Finding open slots…

Real humans only. We'd know.

Having trouble booking? Open scheduler in a new tab

What are you trying to solve?

Tell us in a line and we'll come back with something useful, not a generic pitch.

We usually help with:

Seeing which third-party scripts run on your site
PCI DSS 6.4.3 and 11.6.1 evidence
Bots, AI agents and account takeover

Prefer to just book a time? Pick a slot instead