• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
drewmcdonald

drewmcdonald

promptCompare

Public
Like
promptCompare
Home
Code
7
.claude
3
backend
2
docs
1
frontend
4
shared
.mcp.json
deno.json
Environment variables
2
Branches
1
Pull requests
Remixes
History
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
.claude
/
skills
/
ai-elements
/
references
/
sandbox.md
Code
/
.claude
/
skills
/
ai-elements
/
references
/
sandbox.md
Search
…
Viewing readonly version of main branch: v71
View latest version
sandbox.md

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.

See scripts/sandbox.tsx for this example.

Installation

npx ai-elements@latest add sandbox

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:

Create val
"use client"; import type { ToolUIPart } from "ai"; import { Sandbox, SandboxContent, SandboxHeader, SandboxTabContent, SandboxTabs, SandboxTabsBar, SandboxTabsList, SandboxTabsTrigger, } from "@/components/ai-elements/sandbox"; import { CodeBlock } from "@/components/ai-elements/code-block"; type CodeSandboxProps = { toolPart: ToolUIPart; }; export const CodeSandbox = ({ toolPart }: CodeSandboxProps) => { const code = toolPart.input?.code ?? ""; const output = toolPart.output?.logs ?? ""; return ( <Sandbox> <SandboxHeader state={toolPart.state} title={toolPart.input?.filename ?? "code.tsx"} /> <SandboxContent> <SandboxTabs defaultValue="code"> <SandboxTabsBar> <SandboxTabsList> <SandboxTabsTrigger value="code">Code</SandboxTabsTrigger> <SandboxTabsTrigger value="output">Output</SandboxTabsTrigger> </SandboxTabsList> </SandboxTabsBar> <SandboxTabContent value="code"> <CodeBlock code={code} language="tsx" /> </SandboxTabContent> <SandboxTabContent value="output"> <CodeBlock code={output} language="log" /> </SandboxTabContent> </SandboxTabs> </SandboxContent> </Sandbox> ); };

Props

<Sandbox />

PropTypeDefaultDescription
...propsReact.ComponentProps<typeof Collapsible>-Any other props are spread to the underlying Collapsible component.

<SandboxHeader />

PropTypeDefaultDescription
titlestringundefinedThe title displayed in the header (e.g., filename).
stateToolUIPart[RequiredThe current execution state, used to display the appropriate status badge.
classNamestring-Additional CSS classes for the header.

<SandboxContent />

PropTypeDefaultDescription
...propsReact.ComponentProps<typeof CollapsibleContent>-Any other props are spread to the CollapsibleContent.

<SandboxTabs />

PropTypeDefaultDescription
...propsReact.ComponentProps<typeof Tabs>-Any other props are spread to the underlying Tabs component.

<SandboxTabsBar />

PropTypeDefaultDescription
...propsReact.HTMLAttributes<HTMLDivElement>-Any other props are spread to the container div.

<SandboxTabsList />

PropTypeDefaultDescription
...propsReact.ComponentProps<typeof TabsList>-Any other props are spread to the underlying TabsList component.

<SandboxTabsTrigger />

PropTypeDefaultDescription
...propsReact.ComponentProps<typeof TabsTrigger>-Any other props are spread to the underlying TabsTrigger component.

<SandboxTabContent />

PropTypeDefaultDescription
...propsReact.ComponentProps<typeof TabsContent>-Any other props are spread to the underlying TabsContent component.
FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
© 2026 Val Town, Inc.