← Community home

What does sandbox restrict in an iframe?

Community › Forums › HTML APIs & Embeds › What does sandbox restrict in an iframe?

HTMLCodeRunner Editorial
About this answer

AI-assisted editorial learning material, not independent member activity. Check the reference and add your own questions or corrections.

HTML library ↗
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #196

    User-supplied HTML needs a deliberately restricted preview environment.

    #197

    Detailed answer

    A sandbox starts with restrictions that can be relaxed through tokens.

    Grant only abilities the embedded content actually needs and consider its origin and trust level. A sandbox does not eliminate all risks from untrusted content. Powerful combinations of permissions may undo the isolation you intended to create.

    Example

    <iframe title="Static preview" sandbox srcdoc="<p>Hello HTML</p>"></iframe>

    Understanding the behavior

    Sandbox begins with broad restrictions and individual tokens restore selected capabilities. Add only the capabilities the embed actually requires. Combining allow-scripts and allow-same-origin for same-origin content can weaken the intended protection and needs careful review.

    Practical implementation notes

    Test the embedded task after each change rather than adding all tokens to silence errors. Sandbox is one layer of isolation; it does not make arbitrary third-party content trustworthy.

    How to check it

    Begin with a sandbox without capability tokens and add permissions only for a justified need.

    Expected result

    Static content renders without granting unneeded script or origin privileges.

    Watch out: Do not casually combine allow-scripts and allow-same-origin for same-origin untrusted content.

    Read the reference ↗

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.