Cortex Code Agent SDK¶
The Cortex Code Agent SDK lets you build agentic AI applications using Python and TypeScript. Your agents can read files, run commands, search codebases, execute SQL, and edit code, using the same tools and agent loop that power Cortex Code.
The SDK includes built-in tools for file operations, shell commands, and code editing, so your agent can start working immediately without you implementing tool execution.
Get started¶
Prerequisites¶
Requirement |
Details |
|---|---|
Cortex Code CLI |
Install with |
Snowflake connection |
Configured through Snowflake CLI connection settings, typically in
|
Node.js (TypeScript) |
Version 18.0.0 or later |
Python (Python SDK) |
Version 3.10 or later |
1. Install the Cortex Code CLI¶
Install the CLI:
2. Install the SDK¶
Install the SDK from npm or PyPI:
3. Configure your Snowflake connection¶
The SDK authenticates through your Snowflake CLI connection settings. Add a connection to
~/.snowflake/connections.toml or use an existing setup in ~/.snowflake/config.toml
(see Configuring connections):
The SDK uses the CLI’s default connection unless you specify one explicitly through the connection option.
If the Cortex Code CLI is not on your PATH, point the SDK at it by setting
CORTEX_CODE_CLI_PATH=/path/to/cortex or by passing cliPath (TypeScript)
or cli_path (Python) in the SDK options.
4. Run your first agent¶
The following example creates an agent that explores your project and summarizes what it does:
For a more complete tutorial, see Quickstart.
Capabilities¶
Built-in tools¶
Your agent can read files, run commands, execute SQL, and search codebases without additional configuration. Available tools can vary by environment and runtime capabilities:
Tool |
Description |
|---|---|
Read |
Read any file in the working directory |
Write |
Create new files |
Edit |
Make precise edits to existing files |
Bash |
Run terminal commands, scripts, and git operations |
Glob |
Find files by pattern ( |
Grep |
Search file contents with regex |
SQL |
Execute SQL queries against Snowflake |
Multi-turn sessions¶
You can maintain context across multiple exchanges. The agent retains knowledge of files read, analysis performed, and conversation history:
You can also continue a previous session or fork it into a new one:
MCP servers¶
You can connect to external systems through the Model Context Protocol:
Hooks¶
You can run custom code at key points in the agent lifecycle. Available hook events include PreToolUse,
PostToolUse, Stop, UserPromptSubmit, and more. Hooks are supported in both the Python and TypeScript SDKs.
See the Python SDK reference or the
TypeScript SDK reference for details.
Structured output¶
You can force the agent to return a response matching a JSON Schema:
For more information, see Structured output.
Session control¶
You can control agent behavior through session options:
Option |
Description |
|---|---|
|
Limit the number of agentic turns before the agent stops |
|
Set model thinking effort ( |
|
Interrupt the running agent mid-turn. The session stays alive for further prompts. |
|
Pass environment variables to the agent process |
|
Add extra directories the agent can access beyond |
|
Load plugin directories for custom extensions |
|
Replace or append to the default system prompt |
|
Control which setting files are loaded ( |
Supported models¶
Set the model using the model option. Snowflake recommends "auto" for automatic selection of the highest quality
available model.
Model |
Identifier |
|---|---|
Auto (recommended) |
|
Claude Opus 4.6 |
|
Claude Sonnet 4.6 |
|
Claude Opus 4.5 |
|
Claude Sonnet 4.5 |
|
Claude Sonnet 4.0 |
|
OpenAI GPT 5.2 |
|
Cross-region inference¶
Model availability varies by region. An account administrator can enable cross-region inference to access models not available locally:
For more information, see Cross-region inference.
Next steps¶
Quickstart: Build an agent that finds and fixes bugs
TypeScript SDK reference: Full TypeScript API reference and examples
Python SDK reference: Full Python API reference and examples
Multi-turn sessions and streaming input: Maintain context across multiple exchanges
MCP servers: Connect external MCP servers
System prompts: Customize agent behavior with system prompts
Handle approvals and user input: Control which tools the agent can use
Structured output: Return validated JSON from agent workflows
Streaming output: Stream responses in real-time
Hooks: Run custom code at key points in the agent lifecycle
Legal notices¶
Where your configuration of Cortex Code uses a model provided on the Model and Service Pass-Through Terms, your use of that model is further subject to the terms for that model on that page.
The data classification of inputs and outputs are as set forth in the following table.
Input data classification |
Output data classification |
Designation |
|---|---|---|
Usage Data |
Customer Data |
Covered AI Features [1] |
For additional information, refer to Snowflake AI and ML.