Cursor SDK: run Cursor's agent from your own code
What the Cursor SDK is, how to install @cursor/sdk or cursor-sdk, set an API key, run a local or cloud agent, use MCP servers, and keep runs safe.
By the Kipt team · Updated 24 November 2026 · 9 min read
What is the Cursor SDK?
The Cursor SDK is a package that lets you call Cursor's agent from your own code, so a script, a CI job or a product feature can start the same agent that runs in the Cursor app. Cursor's TypeScript SDK docs open with that idea: the agent from the IDE, CLI and web app "is now scriptable from TypeScript". There is also a Python SDK with the same shape.
You use it when typing into the editor is not the right interface. Typical jobs are a bot that fixes a failing check, a worker that triages bug reports, a review pass that runs on every pull request, or an agent embedded in your own app. Cursor lists those same examples next to its Cookbook of runnable projects.
As of 24 November 2026, the TypeScript docs page shows no beta or general availability label, so this guide does not claim either. Check the page itself before you build something that depends on it.
Three ideas run through the whole API, taken from the docs:
| Concept | What it is |
|---|---|
| Agent | A durable container for conversation state, workspace config and settings. It survives across several prompts. |
| Run | One prompt submission. It owns its stream, status, result and cancellation. |
| SDKMessage | A normalized stream event emitted during a run, with the same shape in every runtime. |
How do I install the Cursor SDK and set an API key?
Install the package from npm, set an API key, and you are ready to create an agent.
npm install @cursor/sdk
export CURSOR_API_KEY="your-key"
The package name starts with @, and the docs state that the bare cursor/sdk does not exist on npm. The SDK needs Node.js 22.13 or later (checked 24 November 2026). It ships platform binaries for sandboxing and ripgrep, so Cursor describes it as a Node-first package.
For Python, the docs give pip install cursor-sdk and say it requires Python 3.10 or later.
On keys, the docs say to set CURSOR_API_KEY or pass apiKey before creating an agent. Two kinds of key work, for local and cloud runs alike:
- A user API key from the Cursor Dashboard.
- A service account API key from Team settings, described in Cursor's service accounts docs.
Team Admin API keys are not supported yet. If you have no key provisioned and run the SDK on a machine where a person can sign in, Cursor.auth.login() opens a browser login and stores a key. The docs say it lasts 90 days by default and is saved in ~/.cursor/sdk/auth.json. The SDK does not pick up credentials from a local Cursor install on its own.
What does a minimal Cursor SDK script look like?
A minimal script creates an agent, sends one prompt and prints the stream. This is the quick start from Cursor's TypeScript docs:
import { Agent } from "@cursor/sdk";
const agent = await Agent.create({
apiKey: process.env.CURSOR_API_KEY!,
model: { id: "composer-2.5" },
local: { cwd: process.cwd() },
});
const run = await agent.send("Summarize what this repository does");
for await (const event of run.stream()) {
console.log(event);
}
Each event is a discriminated SDKMessage, so you branch on event.type. The docs show assistant, thinking, tool_call and status among the types. If you do not need a live stream, call await run.wait() instead. The result has a status of "finished", "error" or "cancelled", and the final assistant text is on result.result.
A second agent.send() on the same agent loads the earlier conversation, so you can say "Fix it and add a regression test" after a first run found a bug.
The Python version in Cursor's docs is shorter because the sync client returns text directly:
import os
from cursor_sdk import Agent, LocalAgentOptions
with Agent.create(
model="composer-2.5",
api_key="crsr_key",
local=LocalAgentOptions(cwd=os.getcwd()),
) as agent:
print(agent.send("Summarize what this repository does").text())
For a one-shot job (create, run, dispose) the docs also describe Agent.prompt().
Should I use a local or a cloud agent?
Use a local agent when the code and the files are already on the machine running your script, and a cloud agent when they are not. You choose by passing local or cloud to Agent.create(), with the same CURSOR_API_KEY for both.
| Local | Cloud (Cursor-hosted) | |
|---|---|---|
| Where the agent loop runs | Inline in your Node process | An isolated VM that Cursor runs, with your repo cloned in |
| Files | Read from disk | The cloned repository |
| Good for | Dev scripts and CI checks against a working tree | Callers without the repo, many agents in parallel, runs that outlive the caller |
| Sandbox option | local.sandboxOptions, off by default |
Always in an isolated VM |
| Local-only options | systemPrompt, tools, disallowedTools, customTools, autoReview, custom store |
Not available |
| Cloud-only options | Not available | repos, autoCreatePR, workOnCurrentBranch, envVars |
"Local" describes where the loop and file access run, not the model. The docs say it plainly: "All inference goes through Cursor's hosted models in both modes." You cannot point the SDK at a model you host yourself.
A cloud agent looks like this in the docs:
const agent = await Agent.create({
apiKey: process.env.CURSOR_API_KEY!,
model: { id: "composer-2.5" },
cloud: {
repos: [{ url: "https://github.com/your-org/your-repo", startingRef: "main" }],
autoCreatePR: true,
},
});
With autoCreatePR on, the agent opens a pull request when it finishes. Cloud agents started by the SDK are hidden from the default agent list, and you find them in Cursor Web by choosing Filter > Source > SDK. If you pass cloud with an empty repos list, you get a cloud agent on an empty VM with no repository, but the docs say that must be enabled for your account or team. For more on the product behind this, read our guide to Cursor Cloud Agents.
Which models can I use with the Cursor SDK?
You can use the models your account can see, and the docs tell you to ask the SDK rather than hard-code ids. Cursor.models.list() returns the model ids and parameters available to you. The examples in the docs use composer-2.5, and per-model options go in model.params.
Two details from the docs matter if you have older code:
composer-2andcomposer-2-fastare rerouted to Composer 2.5, because Composer 2 is retired.- Cursor Router is available as
auto-smarton Teams and Enterprise. It takes anoptimize_forparameter with the valuescost,balancedorintelligence.
For a plain-language tour of the models inside the app, see Cursor models. The SDK's list is the source of truth for what your key can call today.
Can the Cursor SDK use MCP servers, subagents and hooks?
Yes to all three, and each can come from code or from files in the project. This is what makes the SDK more than a prompt wrapper.
MCP servers. Pass mcpServers to Agent.create() or agent.send(). Servers can be stdio (a command with optional args and env) or http (a url with optional headers or OAuth auth). A local agent also reads .cursor/mcp.json from the project and ~/.cursor/mcp.json from your home folder, but only if local.settingSources includes "project" or "user". Without settingSources, only inline servers load. Cloud agents also load the user and team servers you configured at cursor.com/agents. If a local MCP server needs OAuth, the SDK cannot open a sign-in for you. It reuses a login you already made in the Cursor app. Our Cursor MCP guide covers the config format, and what is MCP explains the protocol.
mcpServers: {
filesystem: {
type: "stdio",
command: "npx",
args: ["-y", "@modelcontextprotocol/server-filesystem", process.cwd()],
cwd: process.cwd(),
},
},
Subagents. Pass named subagents inline with the agents option, or commit them as .cursor/agents/*.md files with name, description and optional model frontmatter. An inline definition overrides a file with the same name. Each needs a description so the parent knows when to start it, and a prompt.
Hooks. Hooks are file-based only. The docs say there is no programmatic hook callback, and call hooks "a project policy boundary, not a per-run knob". Put them in .cursor/hooks.json. Cloud agents run the project hooks from the cloned repo. See our Cursor hooks guide for the events.
How do I keep a local SDK agent safe?
Turn on the sandbox or add hooks, because a local agent runs tool calls without asking by default. The docs are direct about it: headless mode has no approval prompt, so shell commands, edits and writes run automatically. With the sandbox off, which is the default, the agent can read and write the working directory, run shell commands and reach the network.
You have four controls, all documented:
- Sandbox. Set
local.sandboxOptions.enabled: true. Writes are limited to the working directory, temp directories and paths you allow insandbox.json. Outbound network is denied unless you list hosts in.cursor/sandbox.json. If the host cannot sandbox, the SDK throws aConfigurationErrorthat names the missing piece. - Hooks. Add
beforeShellExecutionorpreToolUsehooks in.cursor/hooks.jsonto allow or block calls. - Toolset limits. Pass
tools: ["read", "grep", "glob", "ls"]for a read-only agent, ordisallowedTools: ["shell"]to remove shell access. Deny wins when both are set. Both are local-only and are not persisted, so pass them again onAgent.resume(). - Auto-review. Set
local.autoReview: trueto route local tool calls through the same classifier the IDE uses.
Cloud runs always execute in an isolated VM, so sandboxOptions does not apply there. Be careful with secrets in cloud runs: the docs say HTTP headers and auth for MCP are handled by Cursor's backend and redacted, but stdio env values are passed into the VM and should be treated as runtime secrets.
How much does the Cursor SDK cost?
The SDK has no separate price in Cursor's docs. They say SDK runs follow the same pricing, request pools and Privacy Mode rules as runs from the IDE and Cloud Agents. Spend appears in your team's usage dashboard under the SDK tag.
Who pays depends on the key. Service account keys bill to the team that owns the service account, and user keys bill to that user's plan. In code, per-run token counts are on run.usage and result.usage, and agent.getUsage() returns billed usage and dollar cost. For local agents getUsage() needs usage access enabled for your account, and cost can take a while to settle after a run ends. For plan names and allowances, use Cursor's pricing page and our Cursor pricing guide, not this one.
What are the limits of the Cursor SDK?
The docs list several, and they decide whether the SDK fits your job:
- Inline
mcpServersare not persisted acrossAgent.resume(), so pass them again. customTools,autoReview, a customstore,tools,disallowedToolsandsystemPromptare local only.- Downloading artifacts for local agents is not implemented.
listArtifacts()returns empty anddownloadArtifact()throws. - Hooks cannot be callbacks, only files.
- A follow-up sent while a cloud run is creating or running throws
AgentBusyError. - Local mode needs Node.js 22.13 or later. The default store needs
node:sqlite, and without itAgent.create()throws aConfigurationErrorunless you configure another store.
Errors share one base class, CursorSdkError, with an isRetryable flag, a code and a requestId you can quote to support. The named types include AuthenticationError, RateLimitError, ConfigurationError and NetworkError.
How does the Cursor SDK relate to the CLI and other agent SDKs?
The SDK is for code that drives the agent, while the Cursor CLI is for a person or a shell script that wants a terminal agent. If you only need a REST interface, Cursor points to its Cloud Agents API. For languages beyond TypeScript and Python, Cursor offers the SDK Bridge, a small local server that exposes the same agent over a Connect/protobuf protocol. Cursor says adapters in other languages are not first-party SDKs.
Other vendors ship SDKs too. Anthropic's is covered in our Claude Agent SDK guide. The big difference to know up front is the one the Cursor docs state: Cursor's SDK always sends inference to Cursor's hosted models. Compare the two on that, on how each handles approvals, and on what each bills, using the official docs for each product.
Where does Kipt fit in?
If you write the same SDK prompts again and again, keep them as saved prompts instead of string literals in scripts. Kipt stores prompts and Agent Skills as Markdown in a private GitHub repo you own, with {{name}} blanks you fill in, and you can paste the result into agent.send(). The SDK is not required for any of that. Cursor also reads skill folders, which our Cursor skills guide explains.
Questions
For TypeScript, run npm install @cursor/sdk. It needs Node.js 22.13 or later (checked 24 November 2026). For Python, run pip install cursor-sdk, which needs Python 3.10 or later.
Yes. Set CURSOR_API_KEY in your environment or pass apiKey (api_key in Python) when you create an agent. Cursor's docs accept user API keys and service account API keys. Team Admin keys are not supported yet.
A local agent runs its loop in your own process and reads files from disk. A cloud agent runs in an isolated Cursor-hosted VM with your repository cloned in. In both cases the model itself is hosted by Cursor.
Yes. Pass mcpServers to Agent.create() or agent.send(), or load .cursor/mcp.json for a local agent by adding project to local.settingSources. Cloud agents also load the servers you set up at cursor.com/agents.
Yes. Cursor documents a Python package, cursor-sdk, with sync and async clients, at cursor.com/docs/sdk/python. For other languages, Cursor points to its SDK Bridge.
Cursor's docs say SDK runs follow the same pricing, request pools and Privacy Mode rules as IDE and Cloud Agent runs. Spend shows in your team's usage dashboard under the SDK tag. Service account keys bill to the team and user keys bill to that user's plan.