<timestamp>Thursday, Aug 6, 2026, 3:56 PM (UTC+2)</timestamp> is there a way to write…
- User
Thursday, Aug 6, 2026, 3:56 PM (UTC+2)
is there a way to write the output of a duckdb_local query to a file in the storage?
Assistant
I'll check how
duckdb_localqueries work and whether their results can be written into storage.Assistant
The prompt already says it's read-only — I'll confirm that in the DuckDB service and docs, and note the intended alternatives for saving results.
Assistant
No —
duckdb_localis intentionally read-only.COPY ... TO,ATTACH, and other write statements are rejected after lockdown.To put query output into storage:
write— for text (CSV, JSON, etc.) under/home/...(e.g./home/exports/result.csv)- Sandbox +
save_files— for binaries like.xlsx(write toout/, then save under/home)
Typical flow: run the query with
duckdb_local, then persist the rows withwriteor the sandbox — not via DuckDB itself.- User
is there a way to write the output of a duckdb_local query to a file in the storage?
- User
Thursday, Aug 6, 2026, 4:04 PM (UTC+2)
what would it take to allow write from this duckdb_local to file in the user storage ; but only there for some intermediary results or stuff saved for later?
Assistant
Let me dig into how the local DuckDB is locked down and how storage writes work today, so I can scope this concretely.
I need to dig into how duckdb_local currently handles reads and what architectural changes would be needed to support writes to user storage. Let me trace through the service layer, query execution, and storage providers to understand the constraints and design decisions involved.
Assistant
Now let me look at the storage file-access layer, the read-only SQL filter, and how
write/save_filesregister files today.I need to examine the file-access, user-files, and sql-filter modules along with the write and save_files tools to understand how quota and size limits work, and whether files require database records, metadata, or attachment listings to be properly registered.
Assistant
Let me check the existing security tests and how
execute_sqlwires into the local query, plus the sandbox'ssave_filespattern for registering produced files.I need to examine the existing security tests in local-query.test.ts and understand how the execute-sql tool invokes local queries and renders results, plus check the file registration pattern used in execute-sandboxed-code.
Assistant
Assistant
Parquet is already supported, so I can move forward with that. Now I need to pull up the DuckDB security documentation from the right source.
Assistant
The docs say
allowed_directoriesis an allowlist that holds even when external access is off, and that it covers writes. That's the load-bearing fact, so let me verify it empirically against the exact DuckDB version the repo pins.The key insight here is that
allowed_directoriesfunctions as a strict allowlist that persists even when external access is disabled, and it applies to file writes just as much as reads. The DuckDB PR demonstrates this working in practice—you can write to permitted paths like/permitted/path/data.csvunder this exact configuration. So there's no need to relax the current security constraints to enable the functionality we need.Rather than rely solely on the documentation, I should verify this empirically with a test script. I'll create a quick test that sets
allowed_directoriesto a temporary directory, disables external access, locks the config, and then attempts aCOPY TOoperation to a file within that allowed directory to confirm it actually works.Assistant
I'm thinking about where the module resolves from—the script's in /tmp so it's looking there. I could move it into the backend directory as a temporary file and clean it up after, or I could set NODE_PATH. Actually, let me just check where @duckdb/node-api is resolving to first.
Assistant
Assistant
- User
Thursday, Aug 6, 2026, 4:09 PM (UTC+2)
go for nao owning the write ; save to should take a format (csv or parquet) lets say
Assistant
Let me read the files I'll be changing.
I'm mapping out the implementation steps: adding a
save_toinput parameter to the SQL execution tool that specifies where and how to save results, threading this through the DuckDB and local query services, updating the tool output component to display the saved file path, and then handling documentation and tests.Let me start by reviewing the relevant files.
Assistant
Assistant
Now I'll implement. Starting with the shared tool schema.
Now I'm ready to start building the shared schema.
Assistant
Now the DuckDB layer, where nao constructs the
COPYitself.Assistant
I need to add the runAndWriteOut function and its helper functions, positioning them early in the file right after runLocalQuery to follow the high-level-first convention.
Assistant
I'm debating whether to use the fully qualified
executeSql.SaveFormator create a type alias for better readability, and I'm checking how other backend files handle imports from the shared tools package to stay consistent with the codebase conventions.Assistant
Now the service layer that resolves the destination and ingests the file into storage.
Assistant
Now the storage helpers: exporting the size check and adding a file-to-storage ingest.
Assistant
Now threading it through the
execute_sqltool.Assistant
Now I'm updating the query handler to preserve the
save_tofield through the existing tool input, merging it with any new input provided while falling back to the existing value if not specified.Assistant
Now the model-facing output so the agent learns where the file landed.
Assistant
Now the tests, updating the existing helper for the new return shape.
I need to track down all the places where
runQueryOnLocalFilesis called and update them for the new return type. I'm checking the test file and other potential callers likenao testand evals. Before diving into the prose updates, I'll run a quick sanity check to make sure the core logic works. Then I'm updating the test helper to extract the.resultproperty from the newLocalQueryOutcomereturn type and creating a separate helper for the save operation.Updating the test file...
Assistant
I need to rework the test that checks for write refusals—the current title doesn't accurately reflect what's being tested since saving is now available. I'll reframe it to clarify that it's rejecting SQL operations that write files directly, regardless of the save_to option. Then I'm adding another test case for when
COPY TOtargets the staging directory with save_to enabled, which should still be rejected.Assistant
All 24 pass. Now the prompt, docs, and skill wording.
All tests are passing, so now I need to update the system prompt, documentation, and the Excel skill wording. I'm also checking the system prompt tests. Looking at the LocalDatabaseBlock section, I need to refine the description of DuckDB's capabilities and limitations to clarify when to use it versus the warehouse.
I'm checking whether LocalDatabaseBlock receives any props about storage availability, since the save_to functionality should only be mentioned when storage is enabled. I see that storage availability is gated elsewhere in the prompt using
hasTool('write'), so I need to understand how that pattern applies here.Assistant
I need to pass the
canSaveResultsprop toLocalDatabaseBlockbased on whether the write tool is available, so the save guidance only shows up when storage is enabled. Let me make that change now.Assistant
I should clarify the storage documentation around line 341 to mention that query results can be saved using save_to, since that's available in PermanentStorageBlock when the write tool is enabled. This would help prevent the agent from unnecessarily using write to manually construct CSV output when save_to already handles that.
Assistant
Now the docs.
Assistant
I should revert the intro edit to keep the original flow intact, and instead update the frontmatter description to reflect the query functionality more clearly.
Assistant
Now let me add a prompt test and run the full backend suite plus lint.
Assistant
I'm realizing that
SystemPrompt({})defaults to having toolNames undefined, which meanshasToolreturns true by default—sohasTool('write')is true andcanSaveResultsbecomes true as well. I should add a test case after the "names the reserved database id" test to verify this behavior.Assistant
The
nullreturn still emits blank lines in the markdown renderer; I'll gate at the call site like the surrounding code does.The
SavedFilecomponent is rendering blank lines when null, so I need to conditionally render it only when the file exists using the&&operator. Let me apply that fix and then check the full test results to reconcile the discrepancy between 12 failed files and 11 failed tests.Assistant
I need to distinguish between the ripgrep failures that were already there and the ones I introduced. With 11 failed test files but only 8 actual test failures, some of those files might have unhandled errors rather than test assertions. Let me pull up the full summary to see which failures are actually mine.
Assistant
These failures are all environmental or pre-existing issues—ripgrep missing, database problems, Slack and OIDC configuration—nothing from my changes. I should verify this by running those specific test suites against the baseline to confirm they were already failing.
Assistant
Those failures are environmental (a
better-sqlite3ABI mismatch and a missing ripgrep binary), unrelated to this change. Let me confirm the suites I touched are green and run lint.The environment issues are pre-existing—a native module built for the wrong Node ABI and a missing ripgrep binary—so they're not caused by my changes. Now I need to verify that the test suites I actually modified all pass.
Assistant
I'll leave
use-agent.tsunformatted since it was already in that state before my changes. Now I'm running lint and the affected tests to make sure the formatting changes didn't introduce any issues, then I'll review the final output. I'm also wondering whether the frontend has a component for displaying execute_sql tool results—sinceexecuteSql.Outputnow includessaved_file, it might be worth checking if we should surface that information to users.Assistant
Let me rename one helper for consistency with its siblings and add coverage for CTEs.
The tool already supports downloading results through the UI, and files are visible in storage, so I don't need to add frontend UI—that would be scope creep since the user asked for backend capability. I'll note that the badge doesn't indicate a file was saved, but since the agent tells them the path and they can see it in storage, I'll leave it as a follow-up item and move on to reviewing the final diff.
In
runQueryOnLocalFiles, if the query succeeds butkeepOutputFilethrows due to size limits, the error propagates correctly and staging gets cleaned up in the finally block—tests confirm this works. TheSAVED_RESULT_TABLEtemp table won't conflict with user SQL since it's created after their query runs. I should verify that DuckDB handlesCREATE TEMP TABLEwrapping a CTE in parentheses, and I'll add a test for that case plus one confirmingsave_toworks with query table references. I'm also reconsidering thereadFileIntoStoragefunction name—something likestoreFileFromDiskmight be clearer about what's happening.Actually,
writeUserFileFromDiskfits better with the existing and naming convention, so I'll go with that rename instead.Assistant
Let me review the final state of the two main files.
Assistant
Let me tidy one redundancy in the main flow.
I'm noticing the
destination && stagingcheck is redundant since staging only exists when destination does, so I can simplify by havingstageOutputFilereturn a combined object instead. I'm refactoring to makesaveToflow through aprepareSavefunction that handles this in one place, then passing that result to the query runner.Refactoring the cleanup logic... Refactoring the return structure...
Assistant
The five failures are all from the storage-tools ripgrep tests, which I've confirmed are due to the missing ripgrep binary. The linter passed without issues, so I'm verifying that these storage-tools failures match exactly with the ripgrep-related tests.
Assistant
I'm noticing a discrepancy —
keys.tsshows 16 changed lines, but it wasn't in the original git status output, and I don't recall modifying it. Let me trace back through what was actually listed initially versus what's appearing now.Assistant
The user's work-in-progress changes were already there, so I didn't modify those. Now I'm wrapping up by updating the todos and writing a summary, then doing a final review of the shared schema formatting and the duckdb service.
Assistant