@cursor/sdk) is a TypeScript SDK for building agents with Cursor. Braintrust traces agent runs, tool calls, and the subagent tasks an agent spawns.
Setup
Install Braintrust alongside the Cursor SDK, then set your API keys. Requires@cursor/sdk v1.0.7 or later.1
Install packages
2
Set environment variables
.env
Auto-instrumentation
To trace Cursor agent runs without modifying your application code, initialize Braintrust normally, then run your app with Braintrust’s import hook to patch the Cursor SDK at runtime.1
Initialize Braintrust and run an agent
2
Run with the import hook
node --import can run the file directly. The Braintrust APIs work the same in TypeScript projects — compile your TypeScript to JavaScript, then run the compiled file with the import hook.If you’re using a bundler, see Trace LLM calls for plugin and loader setup.
Manual instrumentation
To trace the Cursor SDK manually, wrap the imported module yourself withwrapCursorSDK().What Braintrust traces
Braintrust patches the Cursor SDK and captures:- Agent run spans (
Cursor Agent), with the user message as input and the agent’s final output as output. - Tool call spans (
tool: <name>), with the tool arguments as input and the tool result as output. - Subagent spans (
Agent: <description>) nested under a tool span when the agent delegates to a subagent or task. - Token usage metrics (prompt, completion, total, plus cached and cache-creation tokens) from agent turns.
- Run metadata, including the model, agent ID, run ID, status, duration, runtime (local or cloud), and git branch information under
cursor_sdk.*keys. - Errors captured on the agent span.