Embedding BrowserCode
Add a runnable example to your own page, and set the headers it needs.
An embed runs BrowserCode inside your own page: a template, a cloned repo, a coding agent or a Java project, with the panes you choose. Use it to add a runnable example to a tutorial or blog post.
Embeds need a page you control. Except for Java embeds, the page must also send two response headers. If you cannot change the page, use a link instead. See Linking to BrowserCode.
Using the embed builder
The embed builder generates the snippet for you. Choose a template, a GitHub repo, an agent, a Java example or a shared link, select the panes to show, and copy the snippet. A live preview shows the result. In the IDE, the Embed button does the same for the open project.
The rest of this page explains what the builder generates, for when you need to adjust the snippet by hand or the embed does not run on your page.
Choosing a runtime
The runtime your embed uses determines whether your page needs any changes.
A Java embed runs on CheerpJ and has no requirements for the host page. It is a plain iframe, so it works on hosted blogs and CMSs where you cannot set response headers:
<iframe
src="https://browsercode.io/embed?runtime=cheerpj"
style="width: 100%; height: 600px; border: 0"
></iframe> All other embeds run on BrowserPod, which requires SharedArrayBuffer. Browsers only enable SharedArrayBuffer on cross-origin
isolated pages, and an iframe inherits isolation from the top-level page. Your page must send both of
these headers:
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp The iframe must also include allow="cross-origin-isolated":
<iframe
src="https://browsercode.io/embed?framework=vite&view=preview"
allow="cross-origin-isolated"
style="width: 100%; height: 600px; border: 0"
></iframe> If any of the three is missing, the embed shows what is required.
require-corp also blocks cross-origin images, fonts and scripts elsewhere on your page
unless they opt in. Test the whole page, not only the embed.
Choosing what to show
The query string controls what the embed boots and which panes it shows. You can boot a template, a GitHub repo, an agent or a Java example, and show any combination of panes, for example only the preview, or the editor and terminal. For the full list of parameters, see Reference.
In narrow layouts, such as most blog columns, the panes become tabs and the embed opens on the preview. Java embeds open on the Output tab instead, because the Display stays empty until the program opens a window. Every embed shows a small BrowserCode badge that links to browsercode.io.
Examples
The embeds below run in this page, using the query string shown on each. Each one starts a sandbox, so nothing runs until you select Run it.
?framework=vite&view=preview Starts a sandbox in this page, as it would in yours.
?framework=vite&view=editor,preview Starts a sandbox in this page, as it would in yours.
?framework=vite&view=terminal Starts a sandbox in this page, as it would in yours.
?framework=vite Starts a sandbox in this page, as it would in yours.
?runtime=cheerpj Starts a sandbox in this page. Only one Java project can run per site, so close any other BrowserCode tab that is running Java first.
?agent=claude&view=terminal Starts a sandbox in this page and uses this browser's Claude Code session. Close Claude Code in any other tab first. You need to sign in.
Embedding your own project
You can embed a project you saved with Share. Append the link's hash to the /embed URL to run your own files instead of a template. Nothing is stored on a server.
If the editor is visible, the embed includes a Share button. Chrome and Edge
only allow copying from an iframe that has allow="clipboard-write". Without it,
Share reports that the copy failed. You only need this attribute if Share is visible, and it is
unrelated to cross-origin isolation.
Keyless embeds
By default, embeds use our BrowserPod Edge API key, which provides networking and previews. To run
an embed without it, add an empty apiKey= parameter. Keyless embeds have no live preview:
templates still install and run, but cloned repos and agents need a key and show a message instead of
booting.
Embeds cannot use your own API key yet, so do not put a key in an embed URL.
Java embeds
Only one Java embed can run at a time on a site. See Running Java projects.