Why does OpenClaw treat internal hooks as fully trusted code, and what should you check before enabling a workspace hook or a downloaded hook pack?
answer
- where the handler executes
- the Gateway's own rights
- one operator per Gateway
- selection rules, not containment
- --pin, --force and the audit
basics
~20 sOpenClaw internal hooks run inside the Gateway process with its filesystem, network and environment access, and no sandbox wraps them. Before enabling one, read its handler and HOOK.md, see what it stores or sends, and pin where it came from.
solid answer
~50 sHooks are JavaScript or TypeScript modules imported into the Gateway process, so a handler acts with the Gateway's own filesystem, network and environment access, including the credentials under `~/.openclaw`. The agent sandbox does not wrap them. That fits the trust model: one Gateway is one operator's trust boundary, and anyone who can edit `~/.openclaw` already counts as an operator. The loader's guards decide what is selected, not what selected code may do: a workspace hook stays off until its `hooks.internal.entries.<hookKey>.enabled` is true and cannot replace a bundled, plugin or managed hook of the same name; a non-ClawHub hook-pack install asks you to confirm trust, or needs `--force` when non-interactive; npm packs install with `--ignore-scripts`, which does not sandbox the handler. So read the code, install npm packs with `--pin`, keep `hooks.internal.load.extraDirs` to trusted paths, and run `openclaw security audit`.
go deeper
Recall that hooks are code running inside the Gateway itself, with its access to files, network and credentials, and that nothing sandboxes them.
Explain the discovery sources, why workspace hooks need explicit opt-in and cannot replace bundled names, and what --pin, --force and --link each change.
Show a concrete review: read the handler, map its events to the data it sees, trace outbound calls and logs, pin the source, and use the security audit's install findings.
Tie hook trust to the one-operator trust model: decide who may add hook code at all, and move anyone you would not trust with the Gateway's credentials to a separate Gateway.
## Where hook code runs An OpenClaw **internal hook** is a `HOOK.md` file plus a JavaScript or TypeScript handler that the **Gateway** (the always-on daemon that owns channels, sessions and credentials) imports into its own process. When an event fires, the Gateway calls the handler directly. There is no separate worker and no restricted runtime: the handler runs with the **Gateway process's filesystem, network and environment access**. It can read whatever the Gateway user can read, including `openclaw.json` and stored channel and model credentials, and it can contact any host the machine can reach. That is why the documentation calls hooks "trusted code, not sandboxed scripts". The agent **sandbox** and **tool policy** govern the tools the model calls during a run; they do not wrap hook handlers. Placing a hook in an agent's workspace does not put it in that agent's sandbox either. ## Why OpenClaw does not sandbox it OpenClaw's **trust model** supports one trust boundary per Gateway: a single operator or a mutually trusting team. It does not support one Gateway shared by mutually untrusted users. Anyone who can modify Gateway host state, `~/.openclaw` and `openclaw.json` included, is treated as a trusted operator. Hooks follow from that model: - Installing a hook is an operator action, like editing config. - Managed hooks live in `~/.openclaw/hooks/`, inside the state the operator already controls. - A hook is meant for small, fast side effects inside the process, which a sandbox boundary would make slow and awkward. So the question for a reviewer is not "how is the hook contained" but "do I trust this code as much as I trust the Gateway itself". ## What the loader does guard The guards decide **which** hooks load. They do not limit what a loaded hook may do. | Source | Location | Needs explicit opt-in | Can replace a bundled name | | --- | --- | --- | --- | | Bundled | shipped with OpenClaw | no, when selected | n/a | | Plugin | an active plugin's hook directories | through the plugin | yes | | Managed | `<stateDir>/hooks/` | no, when selected | yes | | Extra directories | `hooks.internal.load.extraDirs` | no, when selected | yes, as managed | | Workspace | `<workspace>/hooks/` | yes, always | no | Other boundaries worth knowing: - Handler files must stay inside their hook directory, and symlinks that escape it are rejected. - Any `extraDirs` entry makes hook-name selection **open-ended** across all discovery sources, not only within that directory. - `openclaw plugins install --link` adds a local path to `extraDirs` and runs the code straight from that path, so later edits to the files there take effect after a restart. ## A review checklist before enabling 1. **Read the handler**, not just `HOOK.md`. The Markdown describes intent; the code is what runs. 2. **List its events.** A `message:received` handler sees inbound message content and sender details on every accepted message. 3. **Find every outbound call** (HTTP clients, sockets) and every file write, and decide whether that data may leave the host or persist. 4. **Check what it logs.** Message bodies, whole config objects and credentials should never reach a log. 5. **Check the source.** For npm packs use `openclaw plugins install npm:<package>@<version> --pin` so the exact `name@version` is recorded, and review before supplying `--force`, which only acknowledges a non-ClawHub source. 6. **Run `openclaw security audit`.** It flags hook installs that are not pinned to immutable npm specs or lack integrity metadata. 7. **Enable narrowly.** Named entries in `hooks.internal.entries` form an allowlist; avoid turning on open-ended discovery with `hooks.internal.enabled: true` and no named entries. ## Hook packs and the supply chain - A **hook pack** is a package whose `package.json` lists hook directories under `openclaw.hooks`; it is installed through `openclaw plugins install`. - npm pack and dependency installation run with `--ignore-scripts`. That stops install-time scripts; it does **not** sandbox the handler, which still runs with full Gateway rights when an event fires. - Interactive installs from a non-ClawHub source ask you to confirm trust; non-interactive installs need `--force`. Neither acknowledgement is a review. - Updates follow tracked npm records. When a stored integrity hash differs from the download, the updater warns and asks in the terminal. ## When the code cannot be trusted If a hook comes from someone you would not hand the Gateway's credentials to, the answer is not a tighter hook setting. Do not run it on that Gateway. Run untrusted parties on a separate Gateway, ideally a separate OS user or host, because one Gateway is one trust boundary.
- Is a workspace hook safer than a managed hook because it lives in the agent's workspace?No. Workspace placement is not an agent sandbox: once enabled, the handler runs in the Gateway process with the same rights as any other hook. The differences are about selection: a workspace hook needs an explicit `enabled: true` entry even under open discovery, and it cannot shadow a bundled, plugin or managed hook of the same name.
- Why can a single `hooks.internal.load.extraDirs` entry widen what loads?Any non-empty `extraDirs` makes directory-hook name selection open-ended across every discovery source, not only that path, even when the path points at one hook. Named entries no longer act as the only allowlist. Add only trusted directories, and list `openclaw hooks` afterwards to see what is now selected.
- Hooks run inside the agent sandbox, so a bad hook can only touch the workspace.
- A workspace hook is isolated from the Gateway because it lives in the workspace.
- npm --ignore-scripts at install time means the hook's code cannot do harm.
- Supplying --force is a sufficient review of a non-ClawHub hook pack.
- Adding one path to load.extraDirs only selects hooks from that path.
- One Gateway with hooks from mutually untrusted users is fine if each uses its own workspace.