Cursor Python SDK Basics
Initial Documentation Follow-Along
Tried using the Cursor SDK for Python at work (July 2026) on my Windows machine and kept running into a WinSocket error regardless of what version of Python I used.
Started out by slapping the "Quick Start" code snippet in a script:
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())
Because I don't have in-depth understanding of how Python handles sockets on Windows, I threw Cursor at it using Gemini 3.5 Flash. It turns out that since Python leverages the sockets library used internally by Windows, there's a misalignment in Python between Windows and Unix where Windows only allows its socket "select" method to be used on socket descriptors.
When creating a new Agent object, the Cursor SDK attempts to direct errors to a subprocess, which is not a socket descriptor.
The agent provided some modifications to the Quick Start script, which is similar to the Async Usage snippet that Cursor provides in their documentation:
import asyncio
import os
from cursor_sdk.asyncio import AsyncClient
from cursor_sdk import LocalAgentOptions
async def main():
async with await AsyncClient.launch_bridge(workspace=os.getcwd()) as client:
async with await client.agents.create(
model="composer-2.5",
api_key="crsr_[yourApiKey]",
local=LocalAgentOptions(cwd=os.getcwd())
) as agent:
run = await agent.send("Summarize what this repository does")
print(await run.text())
if __name__ == "__main__":
asyncio.run(main())