On this pageGet the checklist and the hardened compose file

Is It Safe to Run a Self-Hosted AI Agent? Security Checklist

Xtrusio11 min read

Short answer

Yes, but only after you do five things. Read what the agent's repo will run. Lock its container down. Keep its network ports closed to the internet. Move its keys out of the environment. Make it ask you before it does anything it cannot undo. Agents ship with different defaults. For example, the security docs of OpenClaw, a self-hosted AI agent, say its container images are reachable from the network by default. They are not limited to your own machine.

A woman with glasses lit by her laptop screen in a dark room, with the headline Run an AI agent without getting burned
Photo: Christina Morillo / Pexels. Cover design by Xtrusio.

Grab the free kit, a printable checklist and a hardened compose file in one zip. It needs no email.

checklist.pdf and checklist.md list every check with its exact command or setting, a short reason and its source.

compose.yaml puts the hardened settings in one file, and a comment on each setting names where it came from.

Get the checklist and the hardened compose file

Work through the checklist in the same order as this page, from vetting the repo to knowing when to stop. Print it and tick each row as you finish it. The compose file is a template built from Docker's documentation, not a tested setup.

What has already gone wrong, with dates

People have already been hurt by agents and their add-ons. Three risks mattered most in documented cases: ports left open to the internet, malicious code in something the user installed, and stolen keys. The table below gives eight entries, each with its date and the check that answers it.

Documented incidents and the check that answers each one

Date

What happened

Primary source

Check that answers it

2025/07/23

An Amazon Q Developer extension for VS Code shipped with malicious code. AWS says the code failed to run because of a syntax error.

AWS security bulletin

Read the repo

No date published

A compromised Nx package ran a postinstall script that collected credentials.

Nx security advisory

Read the repo

1 September 2025

Cisco found over 1,100 exposed Ollama servers.

Cisco security blog

Keep it off the internet

23 September 2025

CISA said the Shai-Hulud worm had compromised over 500 npm packages.

CISA alert

Keep keys out

31 January 2026

Censys counted 21,639 publicly reachable OpenClaw instances.

eSecurity Planet article

Keep it off the internet

2 February 2026

A Koi Security audit found 341 malicious skills among 2,857 on ClawHub.

The Hacker News report

Read the repo

2 February 2026

NVD listed CVE-2026-25253: OpenClaw before 2026.1.29 sends a token to a gatewayUrl taken from a query string.

NVD entry

Keep it off the internet

February to May 2026

Palo Alto Networks researchers found five more malicious ClawHub skills that were still unblocked.

Palo Alto Networks research

Read the repo

For the attacker's side, read our article on AI agents that hacked company sites; this page is for the person running the agent.

Check 1: Read the repo before it runs

Spend five minutes reading the repo before you install or run anything. These five steps go in order.

  1. Open SECURITY.md in the repo. GitHub tells maintainers to add how to report a vulnerability there, so look for that instruction.
  2. Open the repo's Security tab and click Advisories. Published advisories appear in the tab, or the tab is empty.
  3. Install JavaScript packages with npm install --ignore-scripts. The command finishes and no postinstall output appears.
  4. Open the folder in VS Code Restricted Mode. The Restricted Mode banner appears, and VS Code blocks automatic code execution in the folder.
  5. Read every skill file before you install it. Each file should open as plain markdown, and you should understand every command in it.

The npm step matters because of the Nx package. It ran a postinstall script that scanned the file system and collected credentials the moment it was installed. The npm setting skips those pre and post scripts. Scripts you start yourself, such as npm start, still run.

The skill step matters because skills are markdown packages with broad local system access.

Check 2: Lock the container down

Host

  • Rootless Docker runs the daemon and containers as a non-root user
  • Only trusted users should control your Docker daemon

Add flags to the container itself

Container

  • Mount root filesystem as read only
  • Drop Linux capabilities
  • Disable container processes from gaining new privileges
  • Pids limit
  • Memory limit

Only the Docker host can access the published container port

Network

  • Publish on 127.0.0.1
  • Internal network

The container reads the key from a file

Secrets

  • Mounts each secret as a file

Put the agent in a container and give it as few rights as you can. Four layers work together here: the host, the container flags, the network and the secrets. This section covers the host and the flags.

Start with the host. Rootless Docker runs the daemon and containers as a non-root user. Docker says this helps mitigate potential vulnerabilities in the daemon and the container runtime. Its security page adds that only trusted users should control your Docker daemon. The same page says the daemon needs root privileges unless you opt in to rootless mode.

Next, add flags to the container itself. The table pairs each flag with how Docker describes it.

Container flags and Docker's own description of each

Flag

Docker's description

--read-only

"Mount the container's root filesystem as read only"

--cap-drop

"Drop Linux capabilities"

--security-opt="no-new-privileges=true"

"Disable container processes from gaining new privileges"

--pids-limit

"Tune container pids limit (set -1 for unlimited)"

-m, --memory

"Memory limit"

This single command applies all five flags.

docker run with the five flags

docker run -d \
  --read-only \
  --cap-drop ALL \
  --security-opt="no-new-privileges=true" \
  --pids-limit 256 \
  -m 1g \
  example/agent:replace-me

A compose file can hold the same settings. The kit's compose.yaml is the full version, with the port and the secret added.

services:
  agent:
    image: example/agent:replace-me
    read_only: true
    cap_drop:
      - ALL
    security_opt:
      - no-new-privileges=true
    pids_limit: 256
    mem_limit: 1g

A read-only filesystem can stop an agent that has to write files. If yours fails at start-up, read the error message. Then add a writable folder for that one path only, and keep the rest read only.

Never mount the Docker socket, /var/run/docker.sock, into the agent's container. Docker's docs say bind-mounting the socket and a Docker binary gives the container full access to create and manipulate the host's Docker daemon.

For one product's own sandbox, see our guide to the Claude Code sandbox. A container is a separate layer you can add around any agent.

Check 3: Keep the agent off the open internet

Publish the agent's port on 127.0.0.1 only. In Docker's docs, if you include the localhost IP address with the publish flag, only the Docker host can access the published container port.

The port-publishing page in Docker's docs shows the form docker run -p 127.0.0.1:8080:80. Start the container, then open http://127.0.0.1:8080 on the same machine, and the agent answers. On Docker 28.0.0 or later, the same port on your machine's network address does not answer. In releases older than 28.0.0, hosts on the same local network can reach ports published to localhost.

Some agents only need to reach other containers. For those, use an internal network, which Docker creates with docker network create --internal agent-net. Containers on an internal network may communicate with each other, but not with any other network.

Every agent has its own defaults, so read the security docs of the one you run and find its bind or host setting. OpenClaw's own docs say its container images are reachable from the network by default. The same docs say to pair that default with authentication. Its exposure runbook lists these baseline checks to run before you open access:

openclaw doctor
openclaw security audit
openclaw security audit --deep
openclaw health

Run all of them, then go through each finding they print. You should be able to say, for every finding, whether you fixed it or accepted it. When in doubt, the runbook says to return to loopback-only access and re-run the audit.

A flaw in older OpenClaw versions shows what an exposed instance risks. NVD lists CVE-2026-25253. Versions before 2026.1.29 take a gatewayUrl from a query string and connect to it without prompting. Those versions then send a token to that address. Run version 2026.1.29 or later.

Check 4: Keep API keys out of the environment

Do not put API keys in environment variables. Docker warns that passwords and API keys in environment variables risk unintentional information exposure.

Use Compose secrets instead. Docker mounts each secret as a file at /run/secrets/<secret_name> inside the container. So the agent reads its key from a file, not from the environment. This excerpt gives an agent a secret named api_key.

services:
  agent:
    secrets:
      - api_key
secrets:
  api_key:
    file: ./secrets/api_key.txt

A secrets file lowers the risk of accidental exposure that Docker warns about, but the agent itself can still read the key. So follow OWASP's minimum-access advice and give the agent a key with only the access its task needs.

Your agent must be able to read its key from a file path. Look in its settings for a field that takes a path such as /run/secrets/api_key. If it takes only an environment variable, ask its maintainers for file support or pick another agent.

If the machine or a package you installed is ever compromised, rotate the keys it could reach. After the npm worm, CISA's advice was blunt: "Immediately rotate all developer credentials."

Check 5: Make it ask before anything irreversible

Before an agent deletes, sends or pays, it should need a human yes, and the model must not be able to give it. OWASP's agent cheat sheet says to enforce authorization in the execution component, outside the agent's context.

Put the approval prompt in the tool that runs the action. Do not leave it in the agent's instructions. Injected text can change an instruction, but it cannot change what the tool allows.

Give the agent only the tools its task needs. OWASP's cheat sheet says to "grant agents the minimum tools required for their specific task." A file summarizer has no reason to hold a tool that sends email. If you run a team of agents, give each specialist its own narrow tools, as our AI agent team guide explains.

Keep tool checks and prompt filters apart. OWASP's prompt injection guide says to enforce tool permissions and parameter validation separately. Do not fold them into prompt screening. A delete request that slips past the prompt filter should still be stopped by the tool's own permission check.

Runaway loops can also cost real money. OWASP names this Denial of Wallet. It says unbounded agent loops can cause excessive API or compute costs. Set a spend limit in your provider's billing settings, and pick a monthly figure you could afford to lose.

For one product's version of these approvals, see our guide to Claude Code permissions.

What no checklist can fix: prompt injection

Prompt injection is the one risk no setting removes. An attacker hides instructions in data the agent reads, such as a web page, an email or a file. Because an agent acts on what it reads, a hijack becomes a real action.

NIST says many AI agents are vulnerable to agent hijacking. This is a type of indirect prompt injection that makes an agent take unintended, harmful actions.

The UK government's cyber security agency, the NCSC, goes further. It says prompt injection attacks may never be totally mitigated in the way SQL injection attacks can be. It advises designing to reduce the risk and the impact. Anthropic reports that no browser agent is immune to prompt injection. It says it shares its findings to show progress, not to claim the problem is solved.

So do not count on the model to refuse a hijack. Plan as if some injected instruction will get through. Let the container, the closed ports and the human approval limit what it can do.

Simon Willison names the dangerous mix the lethal trifecta: access to your private data, exposure to untrusted content and a way to send data out. His advice is that the only way to stay safe there is to avoid that combination entirely.

When not to run an agent at all

Sometimes the safe choice is to leave the agent off. Use the table below as a simple stop rule.

Situations that call for stopping, and the safer move for each

Situation

Safer move

The agent reads your private data, takes in content you do not control and can send data out

Keep it off your main accounts. Take away one of those abilities, such as its way to send data out.

Nobody has read the repo or its skill files

Hold off on installing. Read the repo first.

The port cannot stay on loopback only

Keep it away from the internet. Go back to loopback-only access and run the audit again.

The agent can delete, send or pay without a human yes

Take that tool away, or put an approval step in front of it that runs outside the model.

If you also want to be found in AI answers, get your free AI visibility check.

Sources

These are the official pages behind this guide, last checked on 23 November 2026.

  1. docker container run, Docker Docs
  2. Rootless mode, Docker Docs
  3. Docker security, Docker Docs
  4. Port publishing and mapping, Docker Docs
  5. docker network create, Docker Docs
  6. Secrets in Compose, Docker Docs
  7. AI Agent Security Cheat Sheet, OWASP
  8. LLM Prompt Injection Prevention Cheat Sheet, OWASP
  9. Strengthening AI agent hijacking evaluations, NIST
  10. Prompt injection is not SQL injection, UK NCSC
  11. Mitigating the risk of prompt injections in browser use, Anthropic
  12. The lethal trifecta, Simon Willison
  13. Adding a security policy to your repository, GitHub Docs
  14. About repository security advisories, GitHub Docs
  15. npm install, npm Docs
  16. Workspace Trust, Visual Studio Code Docs
  17. Security update for Amazon Q Developer extension, AWS
  18. Malicious versions of Nx published, Nx on GitHub
  19. Detecting exposed LLM servers, Cisco
  20. Widespread supply chain compromise impacting npm, CISA
  21. Researchers find 341 malicious ClawHub skills, The Hacker News
  22. OpenClaw's skill marketplace and the AI supply chain threat, Palo Alto Networks Unit 42
  23. OpenClaw's rapid rise exposes thousands of AI agents, eSecurity Planet
  24. Gateway security, OpenClaw Docs
  25. Exposure runbook, OpenClaw Docs
  26. CVE-2026-25253, NIST National Vulnerability Database

Xtrusio

AI visibility research

Xtrusio is the Perception Engine for B2B brands.