Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

docs: clarify that LDR does not read a .env file (#5649)

LearningCircuitc8596579bea4
diff --git a/bearer.yml b/bearer.yml
index a1e5bc38e1..aa7e1f8669 100644
--- a/bearer.yml
+++ b/bearer.yml
@@ -68,9 +68,10 @@ rule:
# SAFE TO SKIP: Bearer's built-in gitleaks rules flag placeholder URLs
# (discord://YOUR_WEBHOOK_ID/YOUR_TOKEN), test credentials in CI workflows
# (postgres:postgres), and example code in documentation files. All real
- # secrets are managed via environment variables and .env files (which are
- # gitignored). The standalone gitleaks scanner with .gitleaks.toml provides
- # more precise coverage.
+ # secrets are supplied through the server process's environment (never
+ # committed; any local env file used to populate it is gitignored). The
+ # standalone gitleaks scanner with .gitleaks.toml provides more precise
+ # coverage.
- gitleaks
# JavaScript innerHTML/XSS alerts (javascript_lang_dangerous_insert_html)
diff --git a/changelog.d/5649.misc.md b/changelog.d/5649.misc.md
new file mode 100644
index 0000000000..25b628edeb
--- /dev/null
+++ b/changelog.d/5649.misc.md
@@ -0,0 +1 @@
+Docs and `.env.template` now state clearly that LDR itself never loads a `.env` file — it reads only the environment of the server process — while pointing at the file-based mechanisms that *do* work (`docker run --env-file`, Compose `env_file:`, systemd `EnvironmentFile=`), with a new per-deployment persistence table in the environment-configuration guide and a note on the `crawl4ai` dependency's own `load_dotenv()` call.
diff --git a/docs/SearXNG-Setup.md b/docs/SearXNG-Setup.md
index 506cbaddea..7012ad527c 100644
--- a/docs/SearXNG-Setup.md
+++ b/docs/SearXNG-Setup.md
@@ -48,7 +48,9 @@ You have two ways to configure the SearXNG instance URL:
1. **Environment Variable (Recommended for self-hosted instances)**:
```bash
- # Add to your .env file or set in the server environment
+ # Set in the server process's environment (export / docker -e / compose
+ # environment: / systemd EnvironmentFile). LDR itself never loads a .env
+ # file; hand such a file to whatever starts LDR instead.
LDR_SEARCH_ENGINE_WEB_SEARXNG_DEFAULT_PARAMS_INSTANCE_URL=http://localhost:8080
# Optional: Set custom delay between requests (in seconds)
diff --git a/docs/env_configuration.md b/docs/env_configuration.md
index 37086dc756..6e5d6c9ded 100644
--- a/docs/env_configuration.md
+++ b/docs/env_configuration.md
@@ -32,6 +32,71 @@ For example:
For the complete list of all settings, their environment variable names, and default values, see [CONFIGURATION.md](CONFIGURATION.md).
+## Getting Variables Into LDR (and Making Them Persistent)
+
+**LDR itself never loads a `.env` file** — it reads only the environment of
+the server process. (The bundled `.env.template` is a reference of available
+names, not a file LDR opens by itself.) Keeping your values in a file is
+still perfectly fine: hand the file to whatever *starts* LDR rather than to
+LDR — `docker run --env-file <file>`, Compose `env_file:`, or systemd
+`EnvironmentFile=` all read a key=value file and put its contents into the
+process environment, which is what LDR then sees.
+
+The `export` examples on this page are ephemeral: they last until the shell
+session ends. To make a variable survive restarts and reboots, use the
+mechanism that matches your deployment:
+
+| Deployment | Persistent mechanism |
+|---|---|
+| Docker Compose | Add the variable under the service's `environment:` section in `docker-compose.yml` (this is how the bundled compose file sets the SearXNG URL), or point the service's `env_file:` at a key=value file |
+| `docker run` | Pass `-e NAME=value` in the run command, or `--env-file <file>` to load a whole key=value file (persist either in whatever script/systemd unit starts the container) |
+| pip + systemd | Add `Environment="NAME=value"` lines to the unit, or point `EnvironmentFile=` at a root-owned key=value file |
+| pip + manual shell | Add the `export` lines to your shell profile (`~/.bashrc` or similar), or prefix the launch command: `NAME=value ldr-web` |
+| Unraid | Add the variable as a field on the container template |
+
+After changing a variable, restart LDR — values are read at startup (and on
+each settings lookup from the live environment, but a restart is the
+reliable way to guarantee every subsystem sees the change).
+
+### Caveat: a dependency may pull in a stray `.env` (pip installs)
+
+One of LDR's own dependencies, `crawl4ai` (imported on the library
+document-download path), calls `load_dotenv()` at import time — the bare
+call at the top of `crawl4ai/config.py`, verified against crawl4ai 0.9.2.
+
+Because that call passes no arguments, python-dotenv's `find_dotenv()` runs
+with `usecwd=False`, which searches upward from **the calling file** rather
+than from the working directory. The calling file is `config.py` inside
+`site-packages`, so on a pip install the walk goes up through the virtualenv
+and into its parents: a `.env` sitting next to `.venv/` — typically your
+project directory — can be read at that moment and its keys added to the
+process environment.
+
+Any `LDR_*` names in such a file then behave exactly like variables you set
+deliberately: **environment values win over UI settings** and lock the
+corresponding fields in the settings UI. Real variables already exported in
+the environment are not overwritten.
+
+The one exception to the search path is that `find_dotenv()` falls back to
+the current working directory when it detects a REPL, a notebook, a debugger
+or a frozen build. In python-dotenv 1.2.3 (the version `pdm.lock` resolves)
+that condition is
+`usecwd or _is_interactive() or _is_debugger() or getattr(sys, "frozen", False)`,
+where `_is_debugger()` is `sys.gettrace() is not None`. The debugger clause
+is newer than the other three, so an older python-dotenv will not have it.
+
+Under a debugger, then, the file picked up is the one near your CWD instead
+— worth knowing if you are trying to reproduce this deliberately and the
+parent-directory `.env` appears to be ignored.
+
+This is not a supported way to configure LDR — it is a side effect worth
+knowing about if a setting mysteriously refuses to change in the UI.
+Container installs are unaffected in practice: the virtualenv lives at
+`/install/.venv`, so the walk only reaches `/install/` and `/` — neither of
+which is user-writable or mounted from the host in the bundled image — and
+never a user's data directory. If you hit it, remove
+or rename the stray `.env`, or move the virtualenv out from under it.
+
## API Keys
API keys are best set using environment variables for security. Only the `LDR_` prefixed version is needed.
diff --git a/docs/faq.md b/docs/faq.md
index a2a157eb9f..36d901eaf3 100644
--- a/docs/faq.md
+++ b/docs/faq.md
@@ -148,12 +148,16 @@ services:
### Where should I configure settings?
-**Important**: The `.env` file method is deprecated. Use the web UI settings instead:
+**Important**: LDR itself never loads a `.env` file — it reads only the environment of the server process. To keep values in a file, hand the file to whatever starts LDR rather than to LDR: `docker run --env-file <file>`, Compose `env_file:`, or systemd `EnvironmentFile=`. (The bundled `.env.template` is a reference of available variable names, not a file LDR opens by itself.) For most users the web UI is the simplest option:
1. Run the web app: `python -m local_deep_research.web.app`
2. Navigate to Settings
3. Configure your preferences
4. Settings are saved to the database
+(One caveat on pip installs: a dependency, `crawl4ai`, calls `load_dotenv()` when it is imported on the library document-download path, so a stray `.env` in a parent directory of the virtualenv can leak `LDR_*` values into the process — and environment values win over UI settings. See [env_configuration.md](env_configuration.md#caveat-a-dependency-may-pull-in-a-stray-env-pip-installs). Container installs are unaffected.)
+
+To configure via environment variables instead, the variables must be present in the server process's environment. See [env_configuration.md](env_configuration.md) for how to set them persistently for your deployment (Docker Compose, `docker run`, systemd, shell profile, Unraid), including how to load them from a file with `--env-file`/`env_file:`/`EnvironmentFile=`.
+
For a complete reference of all settings, defaults, and environment variables, see [CONFIGURATION.md](CONFIGURATION.md).
### How do I download Ollama models in Docker?
diff --git a/docs/search-engines.md b/docs/search-engines.md
index 45638df930..97a46b5cd9 100644
--- a/docs/search-engines.md
+++ b/docs/search-engines.md
@@ -123,7 +123,7 @@ result = quick_summary(
- **Pricing**: Free tier available, paid plans for higher volume
- **Configuration**:
```bash
- # In .env file or web interface
+ # In the server environment or via the web interface
LDR_SEARCH_ENGINE_TAVILY_API_KEY=your-key-here
```
diff --git a/src/local_deep_research/defaults/.env.template b/src/local_deep_research/defaults/.env.template
index 221aa5fca1..4a03488c9d 100644
--- a/src/local_deep_research/defaults/.env.template
+++ b/src/local_deep_research/defaults/.env.template
@@ -5,6 +5,19 @@
# Format: LDR_ + setting key with dots replaced by underscores, UPPERCASED
# Example: app.debug -> LDR_APP_DEBUG
#
+# IMPORTANT — how these variables reach LDR: this file is a REFERENCE of
+# available names. LDR itself never loads a .env file; it reads only the
+# environment of the server process. To keep your values in a file, hand
+# the file to whatever STARTS LDR rather than to LDR:
+# - docker compose: put them under the service's `environment:` section,
+# or point the service's `env_file:` at your copy
+# - docker run: pass them with -e NAME=value, or load the whole file
+# with --env-file <file>
+# - pip/bare metal: `export NAME=value` before ldr-web (ephemeral), or
+# make it persistent via your shell profile or a
+# systemd unit's `EnvironmentFile=` pointing at a
+# root-owned copy of this file
+#
# For most users, configure settings through the web UI at http://localhost:5000/settings
# LLM API Keys