Sandbox
A collapsible container for displaying AI-generated code and output in chat interfaces.
The Sandbox component provides a structured way to display AI-generated code alongside its execution output in chat conversations. It features a collapsible container with status indicators and tabbed navigation between code and output views. It's designed to be used with CodeBlock for displaying code and StackTrace for displaying errors.
Install using CLI
Install Manually
Copy and paste the following files into the same folder.
Features
- Collapsible container with smooth animations
- Status badges showing execution state (Pending, Running, Completed, Error)
- Tabs for Code and Output views
- Syntax-highlighted code display
- Copy button for easy code sharing
- Works with AI SDK tool state patterns
Usage with AI SDK
The Sandbox component integrates with the AI SDK's tool state to show code generation progress:
Props
<Sandbox />
...propsCollapsibleProps
<SandboxHeader />
titlestring
staterequiredToolUIPart["state"]
classstring
<SandboxContent />
...propsCollapsibleContentProps
<SandboxTabs />
...propsTabsProps
<SandboxTabsBar />
...propsHTMLAttributes
<SandboxTabsList />
...propsTabsListProps
<SandboxTabsTrigger />
...propsTabsTriggerProps
<SandboxTabContent />
...propsTabsContentProps