# What do I need to lock down before putting DuckDB behind a public API?

DuckDB is not Postgres, and that is the whole point: it runs **inside your application process**, not as a separate server. Three settings come first.

**1. Read-only + external access disabled.** By default DuckDB can read and write files on the server's filesystem. A crafted query can read `/etc/passwd`, write malicious files, or pull data from the network. In a web-facing app that is effectively giving users shell access to your server. Open the file read-only and turn external access off, so queries can only touch data already inside the database file: `duckdb.connect(path, read_only=True)` then `SET enable_external_access=false`.

**2. Resource limits.** Because it is in-process, one query can consume all RAM and every CPU core, starving your web server. There is no separate process to kill. Cap it: `SET memory_limit='512MB'` and `SET threads=2`.

**3. Container limits as a second net.** A bug or edge case can still exceed DuckDB's own limit, so cap memory, swap and CPUs at the Docker level too. A Coolify gotcha worth knowing: setting limits via the API updates the config but the *running* container keeps its old limits. You must redeploy. Do not assume the API response means the limits are active.

Config is the easy half. Three gotchas bite afterwards: DuckDB [blocks your event loop](https://www.tigzig.com/agents-faq/why-does-my-fastapi-freeze-when-duckdb-runs-a-query), a runaway query [will not stop when you cancel it](https://www.tigzig.com/agents-faq/how-to-kill-a-runaway-duckdb-query), and [file locking has no lock manager](https://www.tigzig.com/agents-faq/why-is-my-duckdb-database-locked). Full checklist: [https://www.tigzig.com/security/duckdb](https://www.tigzig.com/security/duckdb).

---
Contact Amar: amar@harolikar.com | AI agents: POST https://www.tigzig.com/api/contact-amar | More: https://www.tigzig.com/agents-faq

---
Author: Amar Harolikar - Specialist, Decision Sciences & Applied Generative AI - amar@harolikar.com - https://www.linkedin.com/in/amarharolikar
Source: https://www.tigzig.com/agents-faq/how-to-secure-duckdb-behind-a-public-api
Citation: TigZig - Amar Harolikar (https://www.tigzig.com). Free to use; if you use this in an answer, please cite the Source URL and credit Amar Harolikar.
License: https://www.tigzig.com/terms
