Build Your Own Coding Agent in 30 Minutes with Snowflake’s New code_toolset_all
From the publisher’s feed, collected in the ZeroLabs newsroom.
How I shipped a production-grade AI coding assistant that runs SQL, writes Python, and manages files — all without hosting a single server.TL;DR: Snowflake’s Cortex Agents now support code_toolset_all — a fully managed sandbox with bash, file I/O, SQL execution, and web search. This guide walks you through building a Python SDK client and a Streamlit chat UI that connects to it, complete with keypair auth, SSE streaming, and retry logic. All code is open-source and tested against a live Snowflake account.The Problem I Was Trying to SolveOn August 26, 2026, Snowflake announced the General Availability of the Cortex Agents Coding Agent. This isn’t a preview or beta — it’s production-ready, GA, and available to all accounts. The feature lets you add code_toolset_all to any Cortex Agent request, and Snowflake provisions a fully managed sandbox backed by the same runtime that powers CoCo (Snowflake's built-in coding assistant).I wanted an AI agent that could:Run SQL against my Snowflake account and explain resultsGenerate and execute Python code on demandRead and write files in a persistent workspaceDo all of this via a simple API call — no infra to manageWith GA status, this is now production-ready for real workloads. The catch? There was no Python SDK yet. So I built one.What You’ll BuildBy the end of this article, you’ll have:A production Python SDK that wraps the Cortex Agents APIKeypair JWT authentication (no passwords in code)An SSE streaming parser that handles the real-time response formatA Streamlit chat app where you can talk to your coding agent38 passing unit tests validating every componentArchitecture DiagramYou (Streamlit) → SDK → Cortex Agents API → Managed Sandbox → ResponsePrerequisitesSnowflake account with Cortex Agents enabledPython 3.9+ on macOS30 minutesStep 1: Set Up Keypair AuthenticationThe Coding Agent API uses JWT tokens signed with your RSA private key. Generate one:openssl genrsa 2048 | openssl pkcs8 -topk8 -inform PEM \ -out ~/.ssh/snowflake_rsa_key.p8 -nocryptopenssl rsa -in ~/.ssh/snowflake_rsa_key.p8 -pubout \ -out ~/.ssh/snowflake_rsa_key.pubRegister the public key in Snowflake:ALTER USER MY_USER SET RSA_PUBLIC_KEY='MIIBIjANBgkq...';Step 2: The SDK ArchitectureThe SDK has four core components:| Module | Responsibility || -------------- | -------------------------------- || `config.py` | Environment-based configuration || `auth.py` | JWT token generation and refresh || `streaming.py` | SSE event parsing || `client.py` | HTTP transport with retry |The Key Insight: SSE Event FormatThe Cortex Agents API streams responses using Server-Sent Events. Here’s what the actual wire format looks like:event: response.statusdata: {"message":"Provisioning sandbox","status":"sandbox_provisioning"}event: response.text.deltadata: {"text":"Hello! I'm","sequence_number":2}event: response.text.deltadata: {"text":" Cortex Code.","sequence_number":3}event: responsedata: {"content":[{"type":"text","text":"Hello! I'm Cortex Code."}],"status":"completed"}event: donedata: [DONE]Most SSE parsers assume single-line data: events. The Cortex API uses two-line pairs (event: then data:), which means you need to track state between lines:def iter_events(self, response): current_event_type = Nonefor line in response.iter_lines(): if line.startswith("event: "): current_event_type = line[7:] continue if line.startswith("data: "): data_str = line[6:] event_type = current_event_type or "unknown" current_event_type = None if data_str == "[DONE]": yield StreamEvent(event_type="done") return data = json.loads(data_str) yield StreamEvent(event_type=event_type, data=data)This was the #1 bug in my initial implementation — parsing each line independently produced empty responses.Step 3: The Fluent Builder PatternI wanted the SDK to feel natural for Python developers:from cortex_coding_agent import ClientConfig, CodingAgentBuilderagent = ( CodingAgentBuilder() .with_model("claude-sonnet-4-5") .with_system_instructions("You are a data engineering assistant.") .with_workspace("USER$.PUBLIC.DEFAULT$") .with_permission_policy("always_allow") .build(ClientConfig()))with agent: response = agent.ask("Show me the top 5 tables by row count") print(response.text)The builder validates configuration at build time and constructs the proper API payload:{ "messages": [{"role": "user", "content": [{"type": "text", "text": "..."}]}], "tools": [{"tool_spec": {"type": "code_toolset_all", "name": "code_toolset_all"}}], "models": {"orchestration": "claude-sonnet-4-5"}, "tool_resources": { "code_toolset_all": { "permission_policy": {"type": "always_allow"}, "workspace_mounts": [{"name": "USER$.PUBLIC.DEFAULT$", "mount_path": "/workspace"}] } }}Step 4: Multi-Turn ConversationsHere’s a subtlety that cost me debugging time: the API manages conversation state server-side. You don’t send message history — you send only the latest message, and the API maintains continuity via thread_id.My first implementation accumulated all messages client-side and sent the full history. This caused the API to return empty responses on the 2nd and 3rd turns. The fix:def _build_request(self, user_message: str) -> AgentRequest: message = Message(role=MessageRole.USER, content=[...]) # Send ONLY the current message — API manages history return AgentRequest( messages=[message], thread_id=self._thread_id, # Server tracks state ... )Step 5: Streamlit Chat UI (15 Lines of Logic)The entire chat interface is remarkably simple once the SDK handles the complexity:import streamlit as stfrom cortex_coding_agent import ClientConfig, CodingAgentBuilder@st.cache_resourcedef get_agent(): return ( CodingAgentBuilder() .with_model("claude-sonnet-4-5") .with_permission_policy("always_allow") .build(ClientConfig()) )if prompt := st.chat_input("Ask the coding agent..."): with st.spinner("Thinking..."): reply = get_agent().ask(prompt).text st.markdown(reply)Launch with:export SNOWFLAKE_ACCOUNT=myaccount.region.cloudexport SNOWFLAKE_USER=MY_USERexport SNOWFLAKE_PRIVATE_KEY_PATH=~/.ssh/snowflake_rsa_key.p8streamlit run examples/streamlit_app.pyStep 6: What the Agent Can Actually DoOnce running, the agent handles prompts like:| Prompt | What Happens || --------------------------------------- | -------------------------------------- || “Show me all databases” | Executes `SHOW DATABASES` via SQL tool || “Write a Python script to parse JSON” | Generates code in the sandbox || “Read the CSV at `/workspace/data.csv`” | Uses file read tool || “Search for pandas documentation” | Uses web search tool || “Create a stored procedure for ETL” | Combines SQL + code generation |The sandbox includes numpy, pandas, scipy, matplotlib, and plotly pre-installed. Need more? Add artifact repositories for PyPI access.Lessons Learned1. SSE parsing is harder than it looks. The two-line event/data format is standard SSE, but most tutorials show single-line examples. Always pair event: with the next data: line.2. Don’t accumulate message history. The Cortex API is stateful — it tracks conversations server-side. Sending history causes silent failures.3. Use explicit Python paths on macOS. If you have Anaconda installed, /usr/bin/python3 -m venv .venv avoids path conflicts that cause mysterious PermissionError failures.4. Pin cryptography for Python 3.9 compatibility on macOS. Newer versions have Rust bindings that don't work with the system OpenSSL.5. The sandbox provisions on first call (~10s) then subsequent calls in the same thread are near-instant. Design your UX around this cold-start pattern.Production ChecklistBefore deploying to your team:Use a service account role (not ACCOUNTADMIN)Store private keys in a secrets managerSet permission_policy: always_ask for user-facing appsAdd rate limiting in your application layerMonitor costs via these SNOWFLAKE.ACCOUNT_USAGE views:CORTEX_AGENT_USAGE_HISTORY — Agent-specific token/credit consumptionCORTEX_CODE_CLI_USAGE_HISTORY — CoCo CLI usage (same runtime)CORTEX_REST_API_USAGE_HISTORY — REST API call metricsMETERING_HISTORY — Overall credit consumptionWAREHOUSE_METERING_HISTORY — Warehouse credits (if using warehouse)Disable unused bundled skills to reduce attack surfaceGet the CodeThe complete SDK (38 tests, Streamlit app, deployment SQL) is available as a single zip:Repository structure:cortex-coding-agent/├── src/cortex_coding_agent/ # SDK (10 modules)├── tests/unit/ # 38 passing tests├── examples/streamlit_app.py # Chat UI├── deploy/snowflake/ # Agent DDL + RBAC└── docs/ # Install guide + extension docsConclusionThe Cortex Agents Coding Agent (code_toolset_all) fundamentally changes how you build AI-powered applications on Snowflake. Instead of managing agent loops, sandboxes, and tool infrastructure yourself, you make a single API call and Snowflake handles the rest.In this article, we built a complete Python SDK from scratch — keypair authentication, SSE streaming, a fluent builder, and a Streamlit chat UI — all validated against a live Snowflake account with 38 passing tests.The key takeaway: the barrier to building a production coding agent is now one REST endpoint and a few hours of work. No servers, no containers, no orchestration framework. Just your application, a keypair, and a POST request.Since code_toolset_all automatically inherits new tools as Snowflake adds them, your SDK stays current without code changes. That's the real power of a managed runtime — you focus on the application, not the infrastructure.Found this useful? A 👏 helps others find it too.🏆 Community Awards FinalistHonored to be a finalist for the 2026 Snowflake Community Awards — Open Source Impact (APJ)! If this project helped you, I’d love your vote:🎥 1-min video: How to vote 🗳️ Vote here (Page 6 → APJ → Satish Kumar | LTIMindtree, India)Voting closes Sep 15. Your support means a lot! 💙Follow for weekly Snowflake engineering deep dives:Medium: Snowflake ChroniclesLinkedIn: satishkumar-snowflakeYou may use, share, adapt, and build upon this work. For public redistribution or substantial adaptation, please retain attribution and include a link to the original article or repository and the author’s LinkedIn profile. Private and internal use requires no attribution. Provided “as is” for educational purposes. Please validate and test all examples before using them in production. Views are my own and do not represent any current or former employer.Build Your Own Coding Agent in 30 Minutes with Snowflake’s New code_toolset_all was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.