touss5967 downloadsLive, editable code playgrounds with instant preview inside your notes: HTML/CSS, React, Vue, Svelte, Angular, Solid, Next.js, TypeScript, JavaScript and more.
Embed live, editable Sandpack code playgrounds inside your Obsidian notes. Write a fenced block, get a working React (or Vue, Vanilla, Svelte, Angular…) sandbox that runs in-place.

This plugin relies on Sandpack, which uses CodeSandbox's hosted services. Before you use it, understand what leaves your machine:
*.codesandbox.io), which runs in an iframe. npm packages you import are resolved from CodeSandbox's registry / CDN.*.codesandbox.io.showOpenInCodeSandbox is enabled and you click it, the block's code is exported to codesandbox.io to open it there. This button is off by default.If any of your playground content is sensitive, do not put it in a block, because compiling it will transmit it to CodeSandbox. See Sandpack's docs and CodeSandbox's privacy policy for details on their handling of submitted code.
react, vanilla, vue, angular, svelte, …).main.js, manifest.json, and styles.css from the latest release.<your-vault>/.obsidian/plugins/code-playground/.Write this into any note:
```code-playground
```
That's the minimum. As you type, the plugin automatically assigns each empty block a stable id (shortly after you create it) so its edits can be persisted. From then on, edits inside the playground are saved to a sidecar file (see Storage).
If you paste or write a block that already has some JSON but no id, the automatic scan leaves it alone — run the Assign missing block identifiers command to fill those in.
The legacy
codePlayground(camelCase) fence is still recognized, so existing notes keep working. New blocks usecode-playground.
The block body is JSON. Both id and template are required — a block missing either one renders an inline error view instead of running. Every other field is optional and falls back to the plugin-wide default from the settings tab. You rarely write id by hand: an empty block gets one injected automatically as you type (see Your first playground).
| Field | Type | Default (from settings) | Notes |
|---|---|---|---|
id |
string | auto-generated UUID | Stable identifier used to look up the sidecar. Don't change after creation. |
template |
Sandpack template name | "react" |
Any key from Sandpack's SANDBOX_TEMPLATES. |
theme |
string | "auto" |
"light", "dark", "auto", or any named theme from @codesandbox/sandpack-themes. |
borderColor |
hex color (e.g. "#D3D3D3") |
"#D3D3D3" |
Border around the playground container. |
maxEditorHeight |
positive number (px) | 400 |
Maximum height of the editor panel. |
minEditorHeight |
positive number (px) | 100 |
Minimum height of the editor panel. Must be ≤ maxEditorHeight. |
showEditor |
boolean | true |
Show the code editor pane. |
showPreview |
boolean | true |
Show the live preview pane. |
showConsole |
boolean | false |
Show the console pane below. |
showFileTabs |
boolean | true |
Show file tabs in the editor. |
buttonBackgroundColor |
hex color or omitted | (theme default) | Overrides button background. Omit to inherit from the Sandpack theme. |
buttonTextColor |
hex color or omitted | (theme default) | Overrides button text color. Omit to inherit from the Sandpack theme. |
showOpenInCodeSandbox |
boolean | false |
Show the "Open in CodeSandbox" export button. |
Validation rules (an invalid block renders an inline error view instead of running):
showEditor, showPreview, showConsole must be true.minEditorHeight must be ≤ maxEditorHeight.#RGB or #RRGGBB (case-insensitive).Any field above can be overridden on a single block without touching the plugin settings. Example — a dark-themed React playground with the console enabled and a custom border:
```code-playground
{
"id": "myID",
"template": "react",
"theme": "dark",
"borderColor": "#444",
"showConsole": true
}
```
Plugin defaults apply to every field you don't specify.
Templates are whatever Sandpack ships in SANDBOX_TEMPLATES. Common ones include react, react-ts, vanilla, vanilla-ts, vue, angular, svelte, solid, nextjs, static. See the Sandpack docs for the canonical list.
Themes can be:
"light", "dark", "auto" (built-in strings), or@codesandbox/sandpack-themes — e.g. "amethyst", "aquaBlue", "githubLight", "monokaiPro", "nightOwl".The settings tab dropdown lists every value the current bundle supports.
Open Settings → Code Playground to set vault-wide defaults:
_playgrounds). Changing this only affects new writes; existing sidecars in the old folder stay where they are.Run these from Obsidian's Command palette (Ctrl/Cmd + P), where they appear prefixed with the plugin name, e.g. Code Playground: Insert block. You can also assign a hotkey to any of them in Settings → Hotkeys (search for "Code Playground").
code-playground block that doesn't already have an id, including blocks that already contain JSON. The automatic scan (debounced, while you type) only seeds empty blocks, so run this command whenever a block with existing JSON needs an id. Requires an open note in editing mode.code-playground block at the cursor, pre-seeded with a fresh id and your default template. Requires an open note in editing mode.code-playground block ids, then deletes any sidecar in the playground folder whose id no longer appears anywhere. Shows a confirmation listing the exact files first; deletion follows your Deleted files preference (system trash / vault trash / permanent), so removed sidecars stay recoverable. Available anywhere (no note required).Each block's edits live in their own JSON file inside the vault:
<vault>/<playgroundFolder>/<block-id>.json
The folder defaults to _playgrounds/. The sidecar schema (only version and files are always present; the rest are written as needed):
{
"version": 1,
"files": { "/App.js": "…", "/index.js": "…" },
"activeFile": "/App.js",
"editorWidth": 480,
"hiddenFiles": ["/index.js"]
}
Because the sidecars live in the vault, they sync wherever your vault syncs (Obsidian Sync, iCloud, Dropbox, Git, …). No localStorage, no extra config.
Heads up: deleting a
code-playgroundblock from a note does not delete its sidecar immediately. To reclaim space, run the Remove unused sidecar files command — it deletes according to your Deleted files setting, so the files stay recoverable.
isDesktopOnly: false), but mobile is not yet thoroughly tested. Because Sandpack runs code in an iframe and pulls its bundler from a CDN, previews depend on the mobile webview and a working connection, and some templates may load slowly or unreliably. If you hit a mobile-specific issue, please open one on the repo..trash and other non-indexed locations are not scanned, so if you restore such a note you may need to restore its sidecar from the trash too.npm install
npm run build
Drop the built main.js, manifest.json, and styles.css into <vault>/.obsidian/plugins/code-playground/ to test against a real vault.
MIT — see LICENSE.