Ordered SQL programs
coral codemode sql runs ordered read-only statements
plus CREATE TEMP TABLE ... AS SELECT inside one
private query session.
Branch features: SQL + Python codemode
Run a short SQL program or one Monty Python body against Coral data, using explicit read-only execution surfaces for catalog discovery, querying, and result shaping.
High level overview
SQL codemode gives agents a single-shot SQL workspace with session-local temporary tables. Python codemode gives agents a bounded Python body with Coral host functions. Both surfaces keep Coral's catalog and query behavior behind explicit CLI and MCP adapters.
coral codemode sql runs ordered read-only statements
plus CREATE TEMP TABLE ... AS SELECT inside one
private query session.
coral codemode python runs one Python body through
Monty
and exposes Coral helpers such as sql() and
list_catalog().
Both modes are built for Coral's discovery workflow: inspect schemas, list tables, query catalog tables, and then run the smallest data query that answers the question.
SQL codemode returns result entries for query statements. Python
codemode returns output, captured stdout,
and query_count.
Persistent DDL and DML are rejected in SQL codemode. Python codemode enforces timeout and SQL-call limits, and does not expose filesystem, environment, or network host functions.
CLI commands are explicit. MCP exposes sql_codemode
and codemode only when their corresponding runtime
feature flags are enabled.
Why codemode matters
Cloudflare's codemode docs frame code mode as useful when agents need to chain tool calls with logic, compose results, and work with MCP servers that expose many fine-grained operations. Coral has that shape: agents need to discover a catalog, inspect schema constraints, query data, and transform the result before answering.
A source can expose many tables, functions, columns, required filters, and setup inputs. Codemode keeps that surface behind compact discovery and query primitives.
When the task is tabular, SQL codemode lets the agent stage intermediate results in temporary tables and keep joins, filtering, and aggregation close to the query engine.
When the task needs loops, conditionals, fallback behavior, or custom JSON shaping, Python codemode gives the agent a bounded program instead of a brittle sequence of separate calls.
Both modes keep authority narrow: read-only data access, feature-gated MCP exposure, explicit CLI invocation, and scoped execution limits.
Examples
Both modes are available from the CLI and, when enabled, over MCP. SQL codemode accepts ordered statements; Python codemode accepts one Python body with Coral host functions.
SQL codemode supports read-only statements and session-local temp tables for multi-step analysis.
coral codemode sql --format json --code '
CREATE TEMP TABLE catalog_sample AS
SELECT schema_name, table_name FROM coral.tables LIMIT 5;
SELECT COUNT(*) AS catalog_total FROM catalog_sample;
SELECT * FROM catalog_sample;
'
{
"tool": "sql_codemode",
"arguments": {
"sql": [
"CREATE TEMP TABLE catalog_sample AS SELECT schema_name, table_name FROM coral.tables LIMIT 5",
"SELECT COUNT(*) AS catalog_total FROM catalog_sample",
"SELECT * FROM catalog_sample"
]
}
}
Python codemode can call SQL and catalog helpers, then shape the final response as natural JSON.
coral codemode python --format json --code '
catalog = list_catalog(limit=5)
rows = sql("SELECT schema_name, table_name FROM coral.tables LIMIT 5")
{"catalog_total": catalog["total"], "rows": rows}
'
{
"tool": "codemode",
"arguments": {
"code": "catalog = list_catalog(limit=5)\nrows = sql(\"SELECT schema_name, table_name FROM coral.tables LIMIT 5\")\n{\"catalog_total\": catalog[\"total\"], \"rows\": rows}",
"type_check": true,
"timeout_ms": 60000,
"max_sql_calls": 20
}
}
SQL codemode emits result entries for query statements and skips
temp-table creation entries. Python codemode mirrors the MCP
structured result: output, stdout, and
query_count.
Execution contract
The shared rule is narrow authority. Coral lets agents compose data work without giving them ambient filesystem, environment, network, or persistent mutation powers.
| Surface | Contract |
|---|---|
coral codemode sql |
Explicit CLI command, no feature flag required. |
sql_codemode |
MCP tool exposed only by sql_codemode. |
| Statements | Read-only queries plus session-local temp-table creation. |
| Mutation | Persistent DDL and DML remain rejected. |
| Surface | Contract |
|---|---|
coral codemode python |
Explicit CLI command, no feature flag required. |
codemode |
MCP tool exposed only by codemode. |
| Host functions | sql(), catalog listing, search, table description, and column listing. |
| Limits | Default 60 second timeout and 20 SQL calls, capped at 100. |
Build
SQL codemode and Python codemode share the Coral user model, but they are separate pull requests with separate runtime work.
Executes ordered SQL statements in one private session so temp tables can feed later statements without leaking persistent state.
coral codemode sql
Adds --code, --file, and
--format json paths while keeping inline
coral sql unchanged and read-only.
sql_codemode
Adds a feature-gated MCP tool enabled by
coral features enable sql_codemode or
coral --enable-sql-codemode mcp-stdio.
coral-codemodeRuns one Python body through Monty, dispatches Coral host functions, captures output, and serializes the final value as JSON.
coral codemode python
Adds --code, --file, text or JSON
output, type-check control, timeout, and SQL call limits.
codemodeAdds a feature-gated MCP tool with a structured output schema and the same execution behavior as the CLI adapter.