Skip to content
AgentsCode execution toolMenu

Code execution tool

Code run in a sandbox: the code with line numbers, then output, errors and the result.

Code, output and the result of the last expression.

Installation

$ pnpm dlx shadcn@latest add https://chatcn.dev/r/tool-code-exec.json

Usage

tsx
import { ToolCodeExec } from "@/components/ui/chatcn/tool-code-exec"

<ToolCodeExec state="output-available" language="python" code={code} stdout={stdout} result={value} />
tsx
import { ToolCodeExecPart, toolCodeExecRenderers } from "@/components/ui/chatcn/tool-code-exec"

// One part straight from AI SDK or the chatcn contract
<ToolCodeExecPart part={part} onApprove={approve} onDeny={deny} />

// Or map tool names to renderers for a whole message
renderToolPart(part, { ...toolCodeExecRenderers })

Props

PropTypeNotes
languagestringNames the title: Ran Python
codestring
stdout, stderrstringEach shows only when present
resultstringThe last expression, formatted
attachmentsReactNodeCharts or files the run produced
stateToolDisplayStateThe ToolCall lifecycle: streaming, running, approval, output, error, denied, cancelled
approval, decisionApproval request and the user's answer, as on ToolCall
onApprove, onDeny, onRetrySame callbacks as ToolCall
errorTextReactNodeShown on output-error
durationMs, startedAtnumberOptional. Measured automatically when omitted
variant"card" | "inline"Inline sits on a trace rail
open, defaultOpen, onOpenChangeControlled or uncontrolled details

Keyboard

KeyAction
Enter, SpaceExpand or collapse the details
TabMove through the header, links, copy buttons and approval actions

Motion

  • Inherits ToolCall: the status glyph swaps with a 150 ms blur crossfade and details open over 200 ms.
  • Nothing inside the body animates. Under reduced motion everything snaps.