| name | livecodes/headless-mode |
| description | Run playground without visible UI using SDK methods directly. Load this skill when building Markdown compilers, code formatters, or tools that need compiled output without display.
|
| type | core |
| library | livecodes |
| library_version | 0.13.0 |
| requires | ["sdk-embedding","sdk-methods"] |
| sources | ["live-codes/livecodes:docs/docs/sdk/headless.mdx"] |
This skill builds on sdk-embedding and sdk-methods. Read them first for foundational concepts.
LiveCodes — Headless Mode
Headless mode runs LiveCodes without any visible UI. Use SDK methods to compile code, get output, and react to events.
Setup
import { createPlayground } from 'livecodes';
const playground = await createPlayground({
headless: true,
config: {
markup: { language: 'markdown', content: '# Hello World' },
},
});
const code = await playground.getCode();
console.log(code.markup.compiled);
console.log(code.result);
Core Patterns
Markdown compiler
import { createPlayground } from 'livecodes';
let playground;
async function compileMarkdown(markdown) {
if (!playground) {
playground = await createPlayground({
headless: true,
config: { autoupdate: false },
});
}
await playground.setConfig({
markup: { language: 'markdown', content: markdown },
});
const code = await playground.getCode();
return code.markup.compiled;
}
const html = await compileMarkdown('# Hello\n\nWorld');
console.log(html);
React/JSX compiler
import { createPlayground } from 'livecodes';
let playground;
async function compileJSX(jsxCode) {
if (!playground) {
playground = await createPlayground({
headless: true,
config: { autoupdate: false },
});
}
await playground.setConfig({
script: { language: 'react', content: jsxCode },
});
const code = await playground.getCode();
return code.script.compiled;
}
const compiled = await compileJSX(`
function App() {
return <h1>Hello</h1>;
}
`);
Python interpreter
import { createPlayground } from 'livecodes';
let playground;
async function runPython(code) {
if (!playground) {
playground = await createPlayground({
headless: true,
config: { autoupdate: true },
});
}
const outputs = [];
playground.watch('console', ({ method, args }) => {
outputs.push({ method, args });
});
await playground.setConfig({
script: { language: 'python', content: code },
});
return outputs;
}
const outputs = await runPython('print("Hello from Python!")');
Get result HTML
async function getResultHTML(config) {
const playground = await createPlayground({
headless: true,
config: { ...config, autoupdate: false },
});
await playground.setConfig(config);
const code = await playground.getCode();
return code.result;
}
Watch for changes
const playground = await createPlayground({
headless: true,
config: { autoupdate: false },
});
playground.watch('code', ({ code, config }) => {
console.log('Compiled:', code.script.compiled);
});
await playground.setConfig({
script: { language: 'typescript', content: 'const x: number = 1;' },
});
Common Mistakes
Headless vs Visible Mode
| Aspect | Visible | Headless |
|---|
| Container | Required | Optional |
| UI | Shown | Hidden |
| Use case | User interaction | Programmatic compilation |
When to Use Headless
- Markdown/MDX compiler — Get compiled HTML without display
- Code formatter — Use Prettier via LiveCodes
- Language transpiler — TypeScript → JavaScript, SCSS → CSS
- Testing pipelines — Run and verify code programmatically
- Python/Ruby/Go interpreter — Execute WASM languages and capture output