Skip to main content
The Cursor agent SDK (@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

The auto-instrumentation example uses plain JavaScript so node --import can run the file directly. The Braintrust APIs work the same in TypeScript projects. Compile your TypeScript to JavaScript and run the compiled file with the import hook, or run TypeScript directly with a TypeScript loader.
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 with wrapCursorSDK().

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 named after each tool, such as shell or read, with the tool arguments as input and the tool result as output. Metadata records the tool name (gen_ai.tool.name), tool call ID (gen_ai.tool.call.id), and the status that the SDK reports (cursor_sdk.tool.status).
  • Subagent spans (Cursor Subagent) nested under a tool span when the agent delegates to a subagent or task, with the tool calls that the SDK reports for the subagent nested under them.
  • Token usage metrics (prompt, completion, total, plus cached and cache-creation tokens) from agent turns. Prompt tokens include cached and cache-creation tokens.
  • Run metadata, including the model, agent ID, run ID, status, duration, runtime (local or cloud), and git branch information under cursor_sdk.* keys. Cancelled runs record cursor_sdk.status as cancelled.
  • Errors captured on the agent span, including runs that the SDK reports as failed.

Resources