OpenClaw secrets management is not just a nicer place to park API keys. It is a security boundary cleanup job. If your agent can read `openclaw.json`, `.env`, old auth archives, or generated model files, any plaintext credential sitting there is still part of the agent’s reachable world. SecretRefs help only after you move supported credentials out of those files and prove the old residue is gone.
That point matters because AI agents are different from ordinary web apps. A web app usually has a narrow request handler and a small list of downstream services. An agent may read files, call tools, summarize external pages, run commands, and decide which plugin to use next. If you give that agent a filesystem full of keys, you have turned prompt injection and sloppy tool scope into a credential problem.
The OpenClaw docs are refreshingly direct about the trade-off: plaintext still works, SecretRefs are opt-in, and SecretRefs are not process isolation. That honesty is useful. It means operators can reason about the real protection instead of treating “secret manager” as a sticker on the side of the system.
What OpenClaw secrets management actually protects
The first job is to reduce local blast radius. OpenClaw supports SecretRefs so supported credentials do not need to live as plaintext in configuration. Instead of writing a provider key directly into a config field, you point that field at a reference such as an environment variable, a file provider, an exec resolver, or the OpenClaw shared store.
That sounds simple, but the important word is “supported.” A SecretRef protects a supported credential surface. It does not make every file on the machine safe. The docs call out the ugly list: `openclaw.json`, `.env`, retired auth-profile JSON archives, and generated `agents/*/agent/models.json` files can all hold historical plaintext. If an agent can inspect those paths, the secret is reachable through normal file or shell tools.
So the operator goal is not “use a SecretRef somewhere.” The goal is stricter: migrate every supported credential, scrub old copies, and run `openclaw secrets audit –check` until the audit reports no plaintext residue. Anything less leaves an avoidable hole.
SecretRefs: the contract behind safer credentials
OpenClaw uses one SecretRef shape across supported fields:
{ "source": "env", "provider": "default", "id": "OPENAI_API_KEY" }
The `source` can be `env`, `file`, `exec`, or `store`. The `provider` names the provider config, and the `id` names the specific secret inside that provider. Env refs can also use shorthand strings such as `${OPENAI_API_KEY}` or `$OPENAI_API_KEY` on SecretInput fields.
Each source has different trade-offs. Env refs are familiar, but environment variables are still easy to leak through debug output and process inspection. File refs keep config clean, but the file path and permissions now matter. Exec refs let you bridge to tools such as 1Password, Bitwarden Secrets Manager, HashiCorp Vault, `pass`, or SOPS, but OpenClaw treats exec providers carefully because resolvers can have side effects. Store refs use OpenClaw’s own shared SQLite-backed store.
This is where OpenClaw’s design is more practical than generic advice. You can pick the source that fits the deployment instead of pretending one vault pattern fits every self-hosted box. A solo VPS, a small team gateway, and a regulated production setup do not need the same secret backend.
Runtime snapshots, sentinels, and why fail-closed matters
OpenClaw resolves secrets eagerly during activation into an in-memory runtime snapshot. Runtime requests read from that active snapshot. They do not re-resolve references every time a message is sent or a model call leaves the process.
That choice keeps secret-provider outages off hot request paths. A reload validates mapped owners independently and then publishes one atomic snapshot. Healthy owners refresh. Eligible failed owners may keep their last-known-good value if their ref identities, provider definitions, and non-secret owner contract are unchanged. Strict failures preserve the active snapshot instead of half-applying a broken state.
For model-provider credentials backed by SecretRefs, OpenClaw can mint a process-local sentinel. Internal auth storage, stream options, SDK configuration, logs, and most runtime introspection see a value shaped like `oc-sent-v2…end`, not the actual provider key. The guarded fetch path replaces known sentinels immediately before outbound egress. Unknown sentinel-shaped values fail closed before network activity, so OpenClaw refuses the request rather than accidentally sending a fake or unresolved credential to a vendor.
That fail-closed behavior is the right instinct for an agent gateway. If a credential cannot resolve, a model provider should not silently fall back to a lower-precedence plaintext key. A failed explicit ref means the owner is unavailable, cold, stale, or blocked. It should be visible.
The agent-access boundary is the part people skip
SecretRefs stop credentials from being persisted in supported config surfaces, but they are not a wall around memory. The real value still exists in the same process and appears at the final adapter boundary. The docs say this plainly: sentinels reduce plaintext exposure across the model-call chain, but they are not process isolation.
This is also where AI agent security connects to boring old least privilege. OWASP’s 2025 prompt injection guidance says injected content can lead to sensitive information disclosure, unauthorized function access, command execution in connected systems, and manipulated decisions. Its excessive agency guidance names the usual root causes: too much functionality, too many permissions, and too much autonomy.
Secrets management does not replace those controls. It sits beside them. If an agent has a shell tool, broad filesystem access, and write-capable downstream tokens, a SecretRef can reduce accidental config leakage but cannot make the whole runtime harmless. You still need minimum tool scope, narrow downstream credentials, and human approval for high-impact actions.
Shared secret store: protected secret vs agent-readable env
OpenClaw’s shared secret store is Gateway-wide and team-scoped. You manage it in Settings -> Secrets or with `openclaw secrets store`. The store has two access modes, and the distinction is not cosmetic.
A protected `secret` is write-only after saving. Gateway list results, the Control UI, and CLI list/get output do not reveal the value. A protected secret does nothing by itself until a supported config field references it with a SecretRef or the secret egress proxy uses it.
An agent-readable `env` value is different. Administrators can view it, `store list` and `store get` can return it, and OpenClaw adds it as plaintext to Gateway-hosted commands run through its exec tool. The agent can print it, transmit it, or persist it. That mode is useful when you genuinely want a Gateway-hosted command to receive a normal environment variable, but it is the wrong default for credential-like values.
One more detail deserves space: store values are not encrypted at rest. They live unencrypted in `state/openclaw.sqlite`, protected by the same `0600` file and `0700` directory permissions as other credentials in that database. If your threat model needs stronger storage isolation, the docs point you toward external exec providers such as 1Password or Vault SecretRefs.
Secret egress proxy: useful, narrow, default-off
The secret egress proxy is one of the more interesting pieces in the docs because it deals with a hard problem: how can a Gateway-hosted subprocess use a secret without receiving plaintext?
When enabled, OpenClaw gives Gateway-hosted exec commands process-local sentinels instead of raw store `secret` values. A Gateway-owned loopback proxy then replaces the sentinel in request URLs, headers, and streamed bodies immediately before egress. Each secret must name exact HTTPS hostnames where substitution is allowed. A key bound to `api.openai.com` is not substituted for some random destination.
openclaw secrets store set OPENAI_API_KEY --allow-host api.openai.com
openclaw config set secrets.egressProxy.enabled true --strict-json
openclaw gateway restart
This is a smart safety rail, but it is not a universal shield. Host binding does not prove the allowed service is safe. A bound service could reflect credentials. DNS compromise is still outside the hostname-only policy. Non-HTTPS requests are refused, WebSocket rewriting is not supported, and the proxy applies only to Gateway-hosted exec. Sandbox and remote `node` exec do not receive the proxy variables or sentinels.
Use the proxy when a command truly needs to call a known HTTPS API with a stored secret. Do not use it as an excuse to hand every tool a blank check.
How to migrate without fooling yourself
The OpenClaw operator flow is simple enough to remember:
openclaw secrets audit --check
openclaw secrets configure --apply
openclaw secrets audit --check
The first audit tells you where plaintext still lives. The configure step sets up providers and SecretRefs, then can apply the plan. The second audit is the proof. If it still reports plaintext values at rest, the agent-access risk remains.
Exec providers need extra care. By default, audit skips exec SecretRef resolvability checks to avoid command side effects. Use `openclaw secrets audit –allow-exec` when you actually want to test exec providers. The same caution applies to saved apply plans that include exec refs or providers.
GitHub’s secret scanning docs make the broader cleanup point: when a credential leak is found, rotate the affected credential immediately. Removing the string from history is not enough if the key stayed valid for a while. In an OpenClaw migration, rotation is especially sensible for keys that sat in agent-readable files before the cleanup.
How this fits AI agent security
Google’s Secret Manager guidance recommends least privilege, segmentation by application and environment, minimal IAM roles, audit logs, rotation, and avoiding files or environment variables when a direct secret API is possible. Those rules translate well to agent systems, but the agent twist is sharper: every tool the agent can call becomes part of the credential exposure story.
For OpenClaw, I would use this checklist before calling a deployment production-ready:
- Run `openclaw secrets audit –check` and save the findings.
- Migrate supported provider keys, channel credentials, MCP server env vars, sandbox SSH material, and other supported fields to SecretRefs.
- Pick protected store entries for credential-like values unless a command truly needs plaintext env access.
- Scrub old values from config, `.env`, generated model files, and auth-profile storage.
- Rotate any key that lived in an agent-readable place.
- Use `–allow-exec` deliberately for exec-provider checks.
- Enable the egress proxy only for known Gateway-hosted exec use cases and bind each secret to exact hosts.
- Re-run `openclaw secrets audit –check` and treat a clean result as the migration gate.
The boring parts are the point. Secret handling goes wrong when teams stop at “we moved the key” and skip the old copies, the command paths, and the agent’s actual tool reach.
FAQ about OpenClaw secrets management
Does OpenClaw require SecretRefs?
No. Plaintext credentials still work. SecretRefs are opt-in per supported credential. That makes migration easier, but it also means an existing setup can remain unsafe until you deliberately move credentials and audit the result.
Are SecretRefs the same as process isolation?
No. SecretRefs reduce plaintext at rest and in parts of the runtime path. They do not isolate a process from itself. The real credential still exists in memory and appears at the final adapter boundary.
Should I use `secret` or `env` in the shared store?
Use protected `secret` for credential-like values by default. Use agent-readable `env` only when a Gateway-hosted command must receive plaintext and you accept that the agent can print or persist it.
Is the shared store encrypted?
No. The shared store is stored unencrypted in `state/openclaw.sqlite`, protected by local file and directory permissions. Use an external exec provider such as 1Password or Vault if your threat model needs stronger storage isolation.
What is the safest first step?
Run `openclaw secrets audit –check`. Do not guess. The audit tells you which plaintext residues still matter, and the re-audit tells you whether the migration actually fixed them.
The practical takeaway
OpenClaw’s secrets system is good because it does not pretend to be magic. SecretRefs keep supported credentials out of agent-readable config. Runtime snapshots keep request paths predictable. Sentinels reduce accidental plaintext exposure. The egress proxy narrows where a stored secret can be substituted.
But the migration only counts when the audit is clean. Start there, move one provider, scrub the leftovers, rotate exposed keys, and re-audit. That is less glamorous than a new vault diagram, but it is the part that actually makes the gateway safer.
For the broader security pass, pair this with OpenClaw’s gateway hardening and sandboxing guidance: tighten ingress auth, narrow tool scope, and keep high-impact actions behind a human review step.

