New to Kestra?
Use blueprints to kickstart your first workflows.
Test SQL queries in an ephemeral DuckDB sandbox via Kestra MCP. Let AI agents verify syntax, row output, and query plans safely before touching production.
When AI coding agents (Claude Code, Cursor, Windsurf) assist developers with database queries, backend migrations, or analytics models, they frequently output untested SQL. LLMs can misjudge join conditions, create unintended Cartesian products, or hallucinate non-existent SQL functions. Granting agents live credentials to development or production databases poses serious data privacy and security risks, while preventing them from testing leaves developers to debug broken SQL manually.
This blueprint exposes an ephemeral SQL sandbox and profiler tool over Kestra's native Model Context Protocol (MCP) server. When an agent proposes an analytical query, it invokes test_sql_in_sandbox. Kestra spawns an isolated DuckDB database inside a temporary working directory, seeds baseline customer and order dimensional schemas, captures the EXPLAIN execution plan, and executes the query. The verified row count, query plan, and result preview are returned directly to the agent over MCP, allowing the model to self-correct before code is committed.
test_sql_in_sandbox exposed on Kestra's built-in MCP server via mcp_sql_sandbox (io.kestra.plugin.core.trigger.McpToolTrigger).sandbox_workspace (io.kestra.plugin.core.flow.WorkingDirectory) creates an isolated filesystem boundary for the execution.initialize_sandbox_schema (io.kestra.plugin.jdbc.duckdb.Queries) provisions an in-memory DuckDB database (sandbox.duckdb) and populates baseline tables (customers, orders).explain_query_plan (io.kestra.plugin.jdbc.duckdb.Query) runs EXPLAIN on the agent's proposed SQL to capture scan types and join algorithms when capture_explain_plan is enabled.execute_sandbox_query (io.kestra.plugin.jdbc.duckdb.Query) runs the query, enforcing execution within the sandbox.format_agent_response (io.kestra.plugin.core.output.OutputValues) extracts row counts, applies safety slicing using max_rows, and outputs structured JSON.outputs returns the execution status, row count, query plan, and result records back to the agent in the MCP tool response.Kestra provides native MCP server support, declarative task isolation, and embedded database plugins out of the box. Instead of building custom Python web servers with MCP wrappers and managing ephemeral SQLite or DuckDB lifecycle hooks manually, Kestra handles execution tracking, input validation, working directory cleanup, and tool discovery in a single declarative YAML file.
max_rows slicing (default 25) to protect agent memory limits while returning total row_count.http://localhost:8080/api/v1/main/mcp/default).test_sql_in_sandbox and receives the verified row output and execution plan.initialize_sandbox_schema to ingest real sanitized schema DDL or Parquet files from an S3 bucket or namespace files.httpfs, spatial, or json) to support testing complex analytical functions.