Embed a live Linux CLI terminal in Nextra
Nextra runs on Next.js App Router or Pages Router with React and MDX. Use the script loader via next/script, React wrapper components from kilnvm-react, or an MDX <iframe>.
1. Add KilnVM to Nextra
app/layout.tsx (Next.js App Router + Nextra 4)
import Script from "next/script";
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
{children}
<Script src="https://kilnvm.dev/kilnvm-embed.js" strategy="afterInteractive" />
</body>
</html>
);
}
2. Seed Files, Run Buttons & Production Tips
app/quickstart/page.mdx (or pages/quickstart.mdx)
<div
data-kilnvm-project="proj_your_project_id"
data-kilnvm-theme="dark"
data-kilnvm-cmd="mycli --version"
data-kilnvm-files={JSON.stringify({
"example.json": JSON.stringify({ service: "api", port: 8080 }, null, 2),
})}
/>
- Prefer strategy="afterInteractive" in next/script so hydration finishes before scanning mount divs.
- Add referrerPolicy="origin" whenever embedding /embed iframes across Next.js sites with strict Referrer-Policy defaults.
- Prefer programmatic React mounts? Install kilnvm-react for typed <KilnSandbox /> and <KilnRunButton /> primitives.
3. Try a Live Sandbox Right Now
Click Launch Terminal below to boot a real non-root Linux microVM directly in the page.
Frequently Asked Questions
Does KilnVM work with Nextra static export (output: 'export')?
Yes. Both kilnvm-embed.js and /embed iframes work on purely static exports hosted on Vercel, Cloudflare Pages, or S3.
Is kilnvm-react compatible with Next.js App Router SSR?
Yes. SSR renders a lightweight mount container div cleanly with zero window access during server rendering.
Ready in 5 minutes
Ship live CLI sandboxes inside your docs.
Start free with 300 sessions per month, isolated linux/amd64 microVMs, and zero credit card required.