touss59776 downloadsLive, editable code playgrounds with instant preview inside your notes: HTML/CSS, React, Vue, Svelte, Angular, Solid, TypeScript, JavaScript, Python 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. Python blocks run with Pyodide.

This plugin relies on Sandpack, which uses CodeSandbox's hosted services. Python blocks use Pyodide from the jsDelivr CDN. 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 Sandpack 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.
"template": "python")cdn.jsdelivr.net. Packages that your code imports, such as pandas, download from the same CDN.micropip downloads from PyPI. If your code calls micropip.install(...), the package downloads from pypi.org and files.pythonhosted.org.pyodide.http.pyfetch. It runs in a sandbox with no access to your vault (see Python blocks)..prettierrc support.react, vanilla, vue, angular, svelte, …).pandas loaded from your imports. See Python blocks.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 or "python" |
"react" |
Any key from Sandpack's SANDBOX_TEMPLATES, or "python" (see Python blocks). |
theme |
string | "auto" |
"light", "dark", "auto", or any named theme from @codesandbox/sandpack-themes. |
layout |
"horizontal" or "vertical" |
"horizontal" |
horizontal puts the editor and preview side by side. vertical stacks them so each spans the full note width. See Panel heights. |
borderColor |
hex color (e.g. "#D3D3D3") |
"#D3D3D3" |
Border around the playground container. |
maxEditorHeight |
positive number (px) | 400 |
Maximum height of the editor panel. In the vertical layout, also limits the preview/console pane. |
minEditorHeight |
positive number (px) | 100 |
Minimum height of the editor panel. Must be ≤ maxEditorHeight. In the vertical layout, also limits the preview/console pane. |
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).Panels size to their content, between minEditorHeight and maxEditorHeight:
To change a height:
minEditorHeight, but it can go above maxEditorHeight. A dragged panel keeps its height: Show more ignores it.Content that fills its viewport (for example height: 100vh) has no height of its own. Its preview stays at minEditorHeight until you drag it.
The editor is Sandpack's CodeMirror editor with extra extensions. The Editor settings turn each one on or off for every block (see Settings). Shortcuts apply while the editor has focus.
| Action | Shortcut |
|---|---|
| Find and replace | Ctrl/Cmd + F |
| Next / previous match | F3 / Shift + F3, or Ctrl/Cmd + G / Ctrl/Cmd + Shift + G |
| Select the next occurrence | Ctrl/Cmd + D |
| Select all occurrences | Ctrl/Cmd + Shift + L |
| Go to line | Ctrl/Cmd + Alt + G |
| Fold / unfold at the cursor | Ctrl + Shift + [ / ] (macOS: Cmd + Alt + [ / ]), or click the gutter marker |
| Fold / unfold all | Ctrl + Alt + [ / ] |
| Add a cursor | Ctrl/Cmd + click |
| Select a rectangle | Alt + drag |
| Open autocomplete | Ctrl + Space (it also opens as you type) |
| Format the file | Shift + Alt + F, or Ctrl/Cmd + S when Format on save is on |
Format runs Prettier on the current file. It supports JavaScript, TypeScript, JSX, TSX, JSON, CSS, SCSS, Less, HTML and Vue files. Other file types show a notice. One undo reverts a format. On a syntax error, a notice shows the first line of Prettier's message and the code stays as it is.
Format on save shows no notice. On other file types it does nothing, and on a syntax error it keeps the code as it is.
To set Prettier options, add a /.prettierrc or /.prettierrc.json file to the playground with Manage files. The file must be JSON. Only these keys apply: printWidth, tabWidth, useTabs, semi, singleQuote, jsxSingleQuote, quoteProps, trailingComma, bracketSpacing, bracketSameLine, arrowParens, singleAttributePerLine.
{ "semi": false, "singleQuote": true, "tabWidth": 4 }
Full screen (bottom right of the editor) opens the block in a large modal: the editor on one side, the preview or console on the other. It is the same playground. Edits save to the block and show in it when you close the modal. The modal has its own Format and Manage files buttons.
Escape, the close button, or a click outside it. If the search panel or the autocomplete list is open, Escape closes it first.Set "template": "python" to run Python in a block:
```code-playground
{
"id": "my-python-block",
"template": "python"
}
```
A new block starts with a /main.py that prints the Python version. Python blocks use Pyodide 0.29.0, which is CPython 3.13 compiled to WebAssembly.
Pyodide 1840 ms · packages 3 ms · run 12 ms. Pyodide … ms shows only on the run that loaded Pyodide.Waiting for another block..../main.py runs. Add other files with Manage files. Your code can import other .py files, including packages in folders, and open data files such as /data.csv by their relative path.
Each run starts with fresh globals and a fresh copy of the files. Files that your code writes are not saved.
Pyodide loads the packages that your imports name, if Pyodide has them (for example pandas, matplotlib, pyyaml). The first run that needs a package downloads it.
For other pure-Python packages from PyPI, use micropip. Top-level await works:
import micropip
await micropip.install("cowsay")
matplotlib figures show in the output pane as images:
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4], [1, 4, 9, 16])
plt.title("Squares")
plt.show()
plt.show() shows the open figures after the text printed so far.plt.show() is optional. The figures that are still open at the end of the run show too, as in Jupyter. They also show after an error.plt.style.use(...) apply to their own run only.Python runs in a Web Worker inside a sandboxed iframe (sandbox="allow-scripts"). The worker has an opaque origin, with no access to Obsidian, your vault or Node.js. If the worker can still reach Node.js, the block does not run and shows an error.
theme, layout, borderColor, the editor heights, showEditor and showFileTabs work as for Sandpack blocks. showPreview or showConsole shows the output pane. If both are false, the block shows the editor only and never runs. showOpenInCodeSandbox has no effect. Format does not support .py files.
input() raises an error. The output pane has no keyboard input.import numpy on its own can fail. pandas and matplotlib still load numpy as a dependency.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. The plugin adds one template of its own: python (see Python blocks).
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:
python.horizontal (editor and preview side by side) or vertical (panels stacked, each spanning the full note width). See Panel heights._playgrounds). Changing this only affects new writes; existing sidecars in the old folder stay where they are.Ctrl/Cmd + S in the editor formats the file with Prettier. Shift + Alt + F always formats. See Formatting.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,
"fullscreenEditorWidth": 900,
"rowHeight": 320,
"hiddenFiles": ["/index.js"]
}
editorWidth and fullscreenEditorWidth are the dragged editor widths of the block and of the full-screen modal. rowHeight, editorHeight and paneHeight are the dragged panel heights (see Panel heights).
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. Python blocks are not tested on mobile yet. 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.