Join our Discord community
Code

Sandbox

Interactive code playground with live preview and debugging capabilities. Perfect for React component testing requiring isolated environments with Next.js integration and TypeScript support.

Powered by

Loading component...

Installation

npx shadcn@latest add https://www.shadcn.io/registry/sandbox.json
npx shadcn@latest add https://www.shadcn.io/registry/sandbox.json
pnpm dlx shadcn@latest add https://www.shadcn.io/registry/sandbox.json
bunx shadcn@latest add https://www.shadcn.io/registry/sandbox.json

Features

  • Interactive code editor with syntax highlighting, auto-completion, and intelligent code suggestions
  • Live preview system providing real-time updates as code changes with hot reloading
  • Built-in debugging console capturing runtime errors, warnings, and custom log outputs
  • File explorer interface managing multiple files with tree navigation and file operations
  • Resizable panel layout allowing customizable workspace configuration for optimal development
  • Multi-tab interface switching between code editor, live preview, and console views
  • Multiple file type support handling JavaScript, TypeScript, CSS, HTML, and JSON files
  • Real-time error reporting with inline error highlighting and detailed error messages
  • Sandpack integration powered by CodeSandbox for reliable code execution and preview
  • TypeScript support with complete type checking and IntelliSense capabilities

Examples

Without File Explorer

Loading component...

Use Cases

This free open source React component works well for:

  • Documentation sites - Interactive code examples and live demos built with Next.js
  • Educational platforms - Coding tutorials and interactive learning environments using TypeScript
  • Component libraries - Live playground for testing and showcasing components
  • API documentation - Interactive examples demonstrating API usage using shadcn/ui design
  • Code portfolios - Showcasing projects with editable and runnable code samples
  • Developer tools - Prototyping and testing environments using Tailwind CSS styling

API Reference

Sandbox

PropTypeDefaultDescription
filesSandpackFiles{}Object containing file contents and structure
templatestring"react"Sandpack template (react, vanilla, vue, etc.)
themestring"dark"Editor theme (dark, light, auto)
showTabsbooleantrueWhether to show file tabs in the editor
showLineNumbersbooleantrueWhether to display line numbers in editor
showInlineErrorsbooleantrueWhether to show inline error highlighting
showConsolebooleantrueWhether to display the debugging console
showPreviewbooleantrueWhether to show the live preview panel
showFileExplorerbooleantrueWhether to display the file explorer sidebar
editorHeightstring"400px"Height of the editor panel
classNamestringundefinedAdditional CSS classes for the container

Implementation Notes

  • Component uses Sandpack (CodeSandbox) for reliable code execution and live preview rendering
  • File system supports multiple files with real-time synchronization between editor and preview
  • Error handling includes both compile-time TypeScript errors and runtime JavaScript exceptions
  • Template system supports React, Vue, Angular, Vanilla JavaScript, and custom configurations
  • Panel resizing uses CSS Grid with drag handles for responsive workspace customization
  • Console integration captures console.log, errors, and warnings from executed code
  • Hot reloading ensures immediate preview updates without full page refresh
  • Compatible with shadcn/ui design system and supports custom theming
  • Performance optimized with code splitting and lazy loading for large file sets
  • TypeScript integration provides full IntelliSense and type checking in the editor