AI & automation6 min read · Updated 8 September 2026

How to Secure a Local AI Agent: Token, Loopback, File Roots, Allow-Lists

"It runs locally" is not a security model. Four controls decide what an agent on your machine can actually reach — and all four have sensible defaults you should still check.

How to Secure a Local AI Agent: Token, Loopback, File Roots, Allow-Lists

A local agent is software on your machine that can read files and, if you let it, make network requests. Running it locally removes one category of risk — your documents are not on somebody else's server — and adds another: it is on the same machine as everything else you have.

Four controls decide what it can reach. OpenClerq sets all four to sensible defaults as of release 0.4, but defaults are only useful if you know what they are.

1. The gateway is authenticated

Every endpoint except /health requires a bearer token, generated on first run at ~/.clerq/gateway-token and compared in constant time. There is no development bypass — that was the point of the 0.4 release, and it is a breaking change from earlier versions on purpose.

verifying the gateway is closed
# no token: refused$ curl -s -o /dev/null -w "%{http_code}\n" http://127.0.0.1:18790/skills401# bound to loopback only — not reachable from the network$ lsof -nP -iTCP:18790 -sTCP:LISTENnode    41822  you   22u  IPv4  TCP 127.0.0.1:18790 (LISTEN)# the token is a credential — check nothing else can read it$ ls -l ~/.clerq/gateway-token-rw-------  1 you  staff  64  8 Sep 09:12 gateway-token

2. It listens on loopback

The listener binds 127.0.0.1 unless you deliberately change it. That means nothing on your network can reach it — not a colleague, not a compromised smart device, not someone on the café wifi. If you ever bind it to `0.0.0.0` to reach it from another machine, you have just published a tool-execution API. Put it behind a tunnel instead.

3. File reads are confined to a root

The fs.read tool resolves every path against a realpath-ed root and refuses anything that escapes it — traversal, absolute or UNC paths, NUL bytes, symlinks pointing outside, non-regular files, and anything over the read cap. It also refuses a sibling directory that merely shares a prefix, which is a check that did not exist before 0.4.

capabilities.json
{ "fsRoot": "/Users/you/clerq-workspace", "fsMaxReadBytes": 1048576, "symlinkPolicy": "refuse-outside-root", "httpAllowlist": []}
  • one root, not your home directory
  • empty allow-list = no outbound HTTP
Point fsRoot at a directory made for this, never at your home folder. The agent should be able to reach the documents you are giving it and nothing else — including your SSH keys, your browser profile and every other repo on the machine.

4. Outbound HTTP is off by default

The http.request tool is disabled until httpAllowlist names specific hosts. When enabled, private, link-local and cloud-metadata addresses are blocked on every redirect hop, not just the first — which is what stops a redirect chain being used to reach an internal service or an instance metadata endpoint.

  1. Confirm /skills returns 401 without a token.
  2. Confirm the listener shows 127.0.0.1, not * or 0.0.0.0.
  3. Point fsRoot at a dedicated workspace directory and check the permissions on it.
  4. Leave httpAllowlist empty until something genuinely needs it, then add one host.
  5. Put the skills directory in version control and review changes.

Key takeaways

  • Every endpoint but /health needs a bearer token, checked in constant time, with no dev bypass.
  • The gateway binds loopback. Rebinding it to 0.0.0.0 publishes a tool-execution API to your network.
  • File reads are confined to one root with symlink and traversal checks; point it at a dedicated folder.
  • Outbound HTTP is off until you allow-list a host, and redirects are re-checked at every hop.
  • Sandboxed execution and approvals are 0.5, not 0.4 — until then, treat skill files as code.

Frequently asked questions

Can I run the gateway on a server for my team?

You can, but not by rebinding it to a public interface. Put it behind an authenticated reverse proxy or a private tunnel, and understand that you now have a shared tool-execution service with the operational duties that implies.

What if I leak the token?

Delete the token file and restart the gateway; a new one is generated on the next run. Then work out how it leaked — shell history and screenshots are the two usual routes.

Does a local model make it safer?

It removes the outbound leg, which is the largest remaining exposure if you configured a hosted model. It does not change what the tools can touch on your disk — that is the fsRoot and allow-list, and they are unrelated to which model you use.

Want one of these built for your own workflow?

OpenClerq is open source and yours to run. If you would rather not build the module yourself, tell us what the work actually looks like and we will scope one — or tell you honestly that an off-the-shelf tool does it better.

Describe the workflow

A couple of sentences is enough to get a straight answer.

  • Fixed-scope quote — no obligation
  • Reply within 1 business day

By sending this, you agree that we may contact you about this inquiry.

Prefer to talk first? Reach us directly:WhatsApp+44 7400 733 299Contact page
private AI deployment

About the author

Paxa Media

Written by the Paxa Media delivery team — the same developers, marketers and strategists who build these systems for clients. We are a technology company based in Rijeka, Croatia, and we publish the real numbers we quote rather than "it depends".

Why you can trust this

  • Builds and operates the systems described here — websites, web and mobile apps, automation and integrations
  • Delivered by an in-team staff in Rijeka, Croatia; no outsourced or resold work
  • Price ranges published here are the ranges we actually quote

Keep reading

All tutorials
AI & automation

Run a Local AI Agent on Your Own Machine: OpenClerq in About 15 Minutes

A local administrative agent that never sends your files anywhere. Install it, start the gateway, make the first call, and understand what it is actually doing.

AI & automation

Private, Self-Hosted AI: When Your Data Is Too Sensitive for the Cloud

For most businesses, cloud AI is fine. But when your data is regulated, secret, or simply cannot leave your walls, private AI is the answer. Here is how to tell.

AI & automation

Automate Invoice Intake Without Sending Anything to the Cloud

Invoice processing is the textbook case for a local agent: repetitive, rule-heavy, arithmetic-critical, and full of data you would rather not hand to a third party.