Skip to main content

Running AI agents in Docker Sandboxes without handing them your keys

What I learned hardening Docker Sandboxes (sbx) for coding agents: mounts, secrets, SSH agent forwarding, network policy and VS Code.
AI agents
security
Docker
Author

Julius Aka

Published

December 1, 2026

Schema with the host on the left, the sandbox on the right and a wall in between. Seven doors cross the wall: project folder, LLM API key, GitHub token, SSH agent, host browser, VS Code window and network. GitHub token, SSH agent and host browser are closed. The other four stay open but narrowed, for example to the project folder only or to a placeholder key. Next to each door, the sbx default is noted in grey.

The doors between host and sandbox, and how I closed or narrowed each of them. Figure: Julius Aka.

I wanted to let AI coding agents work on my projects without trusting them with my machine. Docker Sandboxes (sbx) give each agent its own microVM, which sounds like the end of the story. It isn’t.

Over a few evenings of setting up Hermes Agent and Claude in sbx on Windows, I found the same pattern again and again. The isolation is solid, but the convenience features punch holes in it. My SSH agent was forwarded by default. A GitHub token could be injected into HTTPS requests. My entire home folder got mounted read-write because I typed sbx run in the wrong directory.

None of this is a bug. These are defaults chosen so agents just work. But if you want an agent that can’t push to your repos, sign as you or leak your API keys, you have to switch them off yourself. This post is what I learned doing that.

Custom secrets, SSH access and sbxenv.yaml are marked experimental in the sbx docs. I used sbx v0.54.0. Flags may have changed by the time you read this. These are my experiences to the best of my knowledge; you are yourself fully responsible for your agent’s behaviour.

What can go wrong

An agent on your machine runs with your permissions. It can read your SSH keys, use your cloud logins and push to your repos. That’s fine as long as it does what you want. The question is what happens when it doesn’t:

  • It goes rogue, or just gets it wrong. It deletes the wrong folder, force-pushes over your branch, or “fixes” your config. No malice is needed for that.
  • It gets prompt-injected. A README, a GitHub issue, a web page, a dependency or an email the agent reads can carry hidden instructions. From then on, the agent works for whoever wrote them, with your permissions.
  • It sends data to the model provider. Everything the agent reads goes into its context, and that context goes to the LLM provider. If it opens a file it shouldn’t, that file is now on someone else’s servers. Think of your own private documents, or confidential customer files in a company or organization. You can’t firewall this channel, because the agent needs it to work. You can only limit what the agent can read, and pick a provider you trust with what’s left.
  • It exfiltrates or infects. An injected agent can upload your files to an attacker, steal tokens, or install something that stays after the session ends.
  • It becomes a beachhead. An agent on your laptop is inside your network. It can scan and attack your NAS, router and smart home, or your organization’s internal network. You’ve effectively handed an attacker a machine behind your firewall.

How real is prompt injection? More real than I expected. In November 2026, Trajectory Labs published the TL-IPI benchmark. It hides 120 attacks in web pages, emails, documents and messages, across 15 scenarios, and runs them against 12 frontier models, 10 times each. Their headline is blunt: “Prompt injection attack success varies up to 100x across AI models.”

Stacked bar chart of prompt-injection attack success rates for twelve AI models at k = 1, 4 and 8 attempts. Claude Sonnet 5.5 is lowest at 6.7 % for k = 8, Gemini 4 Argon follows at 11.5 %, and the other models range from 68.6 % to 100 %, with Kimi K3.1 Pro at 100 %.

Attack success rate in the TL-IPI benchmark for one, four and eight attacks per model. Source: Trajectory Labs, TL-IPI benchmark, Figure 1, © 2026 Trajectory Labs, PBC.
  • A single attack succeeded in 0.8% of runs on the most robust model (Claude Sonnet 5.5) and 81.3% on the weakest (Kimi K3.1 Pro).
  • If the attacker gets eight tries, more than two thirds succeed on ten of the twelve models. On Grok 4.7 the rate reaches 99.8%, and on Kimi K3.1 Pro 100%.
  • Attacks transferred: several models fell for attacks that weren’t built for them.

The authors note one caveat: they sell prompt-injection data to some labs, so the robust models may look better than they are.

Filters don’t close the gap either. Hermes Guard, a guardrail plugin for Hermes Agent, shows how inventive attacks are. It scans for zero-width and Unicode-tag characters, bidirectional overrides, look-alike letters from other scripts, Base64-encoded payloads and tool calls that reach for credential files. Its own documentation admits that “novel obfuscation that matches no pattern will pass.” Little Canary, an open-source screener for untrusted text, is just as frank. It says it neither sanitizes input nor guarantees safety, and that its tests don’t show it can prevent attacks in general.

So even with the best model and a filter in front, you should assume that an injection will get through eventually. A privacy-friendly provider protects your data, not your agent’s judgment. What you can control is what the agent can reach when that happens.

So the goal isn’t to trust the agent more. It’s to make sure that, when things go wrong, the agent can read, reach and keep as little as possible.

Why not just a container, or a devcontainer?

My first instinct was a Docker container, and then a VS Code devcontainer. Both turned out to be weaker than they look.

A plain container is a convenience boundary, not a security boundary. It shares the host kernel, so a kernel or runtime bug is a container escape. Outbound network is open by default, with no allow-list and no credential proxy. And agents love to run Docker themselves. The usual shortcut is to mount /var/run/docker.sock or add --privileged, which hands the agent root on the host.

A devcontainer is worse, because VS Code deliberately builds bridges back to the host.

  • It forwards your SSH agent and Git credential helper, and copies your .gitconfig, so git push just works. The same goes for anything the agent runs.
  • It exposes an IPC socket that lets processes in the container talk to your local VS Code window, open files there and trigger prompts.
  • It forwards ports automatically.
  • Some of these sockets are injected only when VS Code attaches. You can’t simply unmount them in devcontainer.json; they come back with every attach.
  • The config lives in the repo. The agent can edit .devcontainer/devcontainer.json, and initializeCommand runs on the host at the next rebuild. A one-line change by the agent becomes code execution outside the container.

I spent a fair amount of time hardening devcontainers against these sockets. Then I realized I was fighting the tool’s whole purpose, which is to make the container feel like your machine.

Docker Sandboxes start from the opposite end. Each agent gets a microVM with its own kernel. Outbound traffic is deny-all by default and goes through a host-side proxy. With that, you can actually monitor within the console which web adresses the sandbox talks to. And you can use it to inject secrets (e.g. LLM provider API keys) the sandbox never sees. Mounts, network and credentials are configured on the host, outside the agent’s reach.

Kits make this practical. What a Docker image is for a container, a kit is for a sandbox: a ready-made package that builds a specific VM. It holds the image, the agent’s config and the network rules it needs. One command gives you a working Hermes sandbox, for example: sbx run --kit docker.io/sbx/hermes-agent-kit:latest hermes-agent <path>. You can also build your own kit for your project’s tools, and you can require kits to be signed so you only run trusted ones.

It’s also very new, and that shows. When I first looked in April, a sandbox was capped at 4 GB of RAM, a limit people had already hit with docker sandbox in Docker Desktop (fixed at 4 GB regardless of the memory you gave Docker). And there was no way to mount a GPU on Windows. That rules out anything beyond light coding, like training a model. Here’s what has changed since:

  • sbx is now a standalone CLI that doesn’t need Docker Desktop.
  • GPU passthrough arrived as an experimental feature in v0.38.0 (August 2026). It uses Linux VFIO, so it is Linux-only and still not an option on my Windows machine.
  • Since v0.51.0 (3 November 2026), memory limits can go up to the host’s total RAM.

Custom secrets, SSH access and environment files are all still marked experimental. Expect flags to change between releases.

And you have to sign in to Docker. Even purely local sandboxes require sbx login with a Docker account. Docker’s FAQ says this gives each sandbox a verified identity, enables organization governance and audit logs, and authenticates image pulls. I don’t like it for three reasons:

  • A local isolation tool now depends on an online account and on Docker’s login service being reachable.
  • The CLI’s usage telemetry includes your Docker username unless you disable it with telemetry.disabled.
  • The SSH access to sandboxes is accepted only while you have an active Docker login. An expired session can break unattended runs until you sign in again.

For a tool whose whole selling point is “trust less”, requiring an account with the vendor to run a VM on my own hardware is an odd choice. But for now, it’s the best option I’ve found anyway.

The wall and the doors

The threat model I settled on is simple: assume the agent is compromised, then make sure there is almost nothing it can reach.

The microVM is the wall. What weakens it is every channel back to the host. In my setup I found these doors:

  • Workspace mounts. Whatever you mount, the agent can read and write.
  • The credential proxy. It injects stored secrets, including a GitHub token, into outgoing requests.
  • SSH agent forwarding. The agent can ask your host agent to sign with your keys, even though the keys never leave the host.
  • The host browser. xdg-open in the sandbox opens URLs on your desktop, with your cookies, past the egress policy.
  • VS Code Remote. It adds its own agent forwarding, an IPC socket and credential prompts relayed to the host.
  • The network. Allowed hosts are also possible exfiltration targets.

Schema with the host on the left, the sandbox on the right and a wall in between. Seven doors cross the wall: project folder, LLM API key, GitHub token, SSH agent, host browser, VS Code window and network. GitHub token, SSH agent and host browser are closed. The other four stay open but narrowed, for example to the project folder only or to a placeholder key. Next to each door, the sbx default is noted in grey.

The doors between host and sandbox, and how I closed or narrowed each of them. Figure: Julius Aka.

From that came two rules I now follow without thinking. Real credentials never enter the sandbox. Anything with an outside effect, like pushing, signing or deploying, happens on the host after I’ve reviewed it.

If you really need to add secrets within the sandbox, be sure to use short-term expiration dates and for anything that causes costs, be sure that you have spending limits. Stolen AI keys get expensive fast: in October 2026, breaches at Railway and Zeabur leaked stored API keys, and attackers ran up about $740,000 in unauthorized AI usage at Railway alone. At METR, an attacker simply prompted an agent to reveal its API key and used up $600,000 in credits over three weeks.

Lesson 1: I mounted my whole home folder

With no path, sbx run claude mounts the current directory read-write. PowerShell starts in C:\Users\<you>. Put those two together and one sandbox in my sbx ls had my entire profile mounted, including .ssh, .docker and .claude.

There is no global setting that forbids this. Local policy covers the network only, and mount paths can only be restricted by Docker organization policy. So the fix is habit plus a few tools:

  • Always pass an explicit path, or cd into the project first. I also moved my terminal’s starting directory to a dedicated sbx folder.
  • Choose the least-privileged mode:
Mode How When
Mountless sbx create --name scratch claude (0.42.0+) The agent needs no host files
Clone sbx run --clone claude . The agent writes code in its own Git clone inside the VM and never touches your working tree. To get its changes, run git fetch sandbox-<name> on the host.
Host worktree git worktree add ../x-work, then sbx run ... ../x-work The agent edits files with no git access
Direct sbx run <agent> <path> Low-risk folders only
  • Make sensitive files read-only, even single files: sbx create claude ~/proj ~/proj/.env:ro ~/proj/.git/hooks:ro.
  • Mounts are fixed at creation. To change them, sbx rm the sandbox and create it again. Your host files stay where they are.
  • Check what is mounted with sbx ls (WORKSPACE column) or sbx inspect <name>.

One thing that confused me: a mounted workspace keeps its host path. On Windows, C:\Users\me\sbx\project shows up at /c/Users/me/sbx/project, not at /home/agent/workspace. That folder only matters for mountless sandboxes. I spent a while staring at an empty directory before I worked that out.

For repeatable setups there is sbxenv.yaml (experimental), started with sbx env run. Keep it next to the project folder rather than inside it, so the agent can’t rewrite its own mounts.

Lesson 2: the agent should only ever see a placeholder

I use a privacy-compliant LLM endpoint from a German provider, under strict EU data protection law, with no access for US companies or authorities. The question was how to give Hermes the API key without giving it the key.

sbx answers this with custom secrets. You store the key on the host and bind it to the API’s hostname. Inside the sandbox, the environment variable only holds a placeholder like sbx-cs-<random>. When the agent sends a request to that host, the proxy on the host swaps the placeholder for the real key in the HTTP headers.

sbx secret set-custom --host api.example-llm.de --env MY_LLM_API_KEY --sandbox my-sandbox
# no value flag: sbx prompts for it, so it never lands in shell history

What I’d point out:

  • Scope it. Secrets are global by default, and my first one was. Add --sandbox <name> so a key reaches only the one sandbox that needs it.
  • Headers only. The proxy swaps the placeholder only in HTTP headers, e.g. Authorization: Bearer sbx-cs-…. That works for OpenAI-compatible APIs. An API that expects the key in the URL or the request body gets the placeholder, and the login fails.
  • Use your own variable name, not OPENAI_API_KEY. Some kits write their own placeholder into that one.
  • Sandboxes created before the secret don’t get the placeholder automatically. The CLI warns you about this. Recreating the sandbox is simplest.

The same mechanism serves GitHub. If a github secret is stored, the proxy injects it into HTTPS requests to GitHub, even with no SSH key in sight. My agent cheerfully told me it could push over HTTPS. The fix is to remove the token with sbx secret rm -g github and push only from the host.

A placeholder stops the key from leaking. It doesn’t stop the agent from using up your quota through the proxy while it runs, so keep an eye on rate limits.

Lesson 3: the SSH agent comes back through three layers

I connect VS Code to my sandboxes over SSH (sbx setup ssh, then ssh <name>.sbx). Then I found my host SSH agent inside the sandbox, because sbx forwards it by default. Your private keys stay on the host. But as long as forwarding is on and a key is loaded, any process in the sandbox can ask the agent to sign with it. That lets it log in to GitHub as you and push.

Actually, there are three independent switches, and each of their default settings can bring the SSH agent into the sandbox:

  1. sbx itself. ssh.agentForwardingEnabled defaults to true. Run sbx settings set ssh.agentForwardingEnabled false, then sbx daemon restart, then restart the sandbox.
  2. Your SSH client. In ~/.ssh/config:
Host *.sbx
    ForwardAgent no
    IdentitiesOnly yes
  1. VS Code. Set "remote.SSH.enableAgentForwarding": false and "git.terminalAuthentication": false, then kill the VS Code server inside the sandbox and reconnect.

On your own machine (not in the sandbox), check which settings SSH really uses with ssh -G <name>.sbx: the output should contain forwardagent no. Why check at all? For every option, SSH uses the first value it finds, and the block that sbx adds sits at the top of your config. If something up there switches forwarding on, your own ForwardAgent no further down is silently ignored.

The tricky part is verifying it. An empty SSH_AUTH_SOCK proves nothing. sbx exports the variable anyway, and VS Code adds a symlink like vscode-ssh-auth-sock-* -> /run/ssh-agent.sock. What matters is whether some socket still answers. To test these sockets in the sandbox:

for s in $(find / \( -path /proc -o -path /sys \) -prune -o -type s -print 2>/dev/null); do
  echo "== $s"; SSH_AUTH_SOCK=$s timeout 2 ssh-add -l; done

Every one should fail. Run it again while VS Code is connected. You’ll also see vscode-ipc-* and vscode-git-* sockets. They hold no keys, but they let sandbox processes open files in your editor and trigger credential prompts on your desktop. I disconnect VS Code when an agent runs unattended.

One more detail: some kits fill the sandbox’s authorized_keys from the forwarded agent and break once forwarding is off. For those, add your own public key by hand.

Working in VS Code as usual

None of this means giving up your editor. VS Code’s Remote-SSH extension connects to the sandbox, and from then on it feels like local development: your extensions, terminal, debugger and Git view, with everything running inside the microVM.

Setup, once per machine

  1. Install the Remote - SSH extension in VS Code.
  2. Run sbx setup ssh. It writes a managed Include block into ~/.ssh/config, so every sandbox is reachable as <name>.sbx. No SSH key is needed, because the connection is authenticated through your Docker login. On Windows, check the generated line (see Windows gotchas).
  3. Add the hardening block to ~/.ssh/config:
Host *.sbx
    ForwardAgent no
    IdentitiesOnly yes
  1. Add these to your VS Code user settings (settings.json):
{
  // no SSH agent into the sandbox
  "remote.SSH.enableAgentForwarding": false,
  // no relaying Git credential prompts to your desktop
  "git.terminalAuthentication": false,
  "git.useIntegratedAskPass": false,
  // download the VS Code server and extensions on the host and copy them in,
  // so the sandbox needs no egress for marketplace or update hosts
  "remote.SSH.localServerDownload": "always",
  "remote.downloadExtensionsLocally": true,
  // don't auto-forward ports that sandbox processes open
  // (extensions and some URLs can still forward ports)
  "remote.autoForwardPorts": false,
  // skip the OS prompt for sandbox hosts
  "remote.SSH.remotePlatform": { "*.sbx": "linux" }
}

Every day

  1. Create the sandbox from your project folder: sbx create --name myproj claude C:\Users\<you>\sbx\myproj.
  2. In VS Code, press F1, choose Remote-SSH: Connect to Host… and enter myproj.sbx. A stopped sandbox starts on its own.
  3. Open the folder at its host path, e.g. /c/Users/<you>/sbx/myproj, not /home/agent/workspace.
  4. Start the agent in VS Code’s integrated terminal, or use its extension, which now runs inside the sandbox.

After changing any of these settings, run Remote-SSH: Kill VS Code Server on Host… and reconnect, because the old server keeps its old configuration.

What’s left. While VS Code is connected, its server inside the sandbox keeps a channel open to your editor. Sandbox processes can use it to open files in your window. That’s a much smaller door than an SSH agent, but it’s a door. When an agent runs unattended for long, I disconnect VS Code and check back later.

Lesson 4: deny-all, except for what kits quietly allow

sbx denies outbound traffic by default, which is great. But kits ship their own allow rules. The Hermes kit, for example, opens OpenRouter, OpenAI, Anthropic, GitHub Copilot, opencode and the GitHub hosts. If you only use one endpoint, the rest is just exfiltration surface.

Kit rules can’t be deleted, only overridden.

sbx policy allow network --sandbox my-sandbox api.example-llm.de
sbx policy deny  network --sandbox my-sandbox "openrouter.ai,*.openrouter.ai,api.openai.com,api.anthropic.com,opencode.ai"
sbx policy ls my-sandbox --wide     # SOURCE kit/local/org, plus rule IDs
sbx policy log my-sandbox           # what got blocked

What I learned the hard way:

  • Scope every rule with --sandbox. I had a global and a sandbox-scoped allow rule for the same host without noticing.
  • Delete rules by ID (sbx policy rm network --id <uuid>). Matching by hostname often fails for rules created with a port or protocol. A global rule needs no --sandbox; a sandbox rule needs it.
  • Use sbx policy log before guessing hostnames. It’s the quickest way to find out why something like the VS Code server download keeps failing.

The sbx policy --help text is refreshingly honest. Rules match the hostname a connection names. A denied host that shares an IP with an allowed one can still be reached on connections the proxy doesn’t decrypt, after the first request on cleartext HTTP, or on connections that name no host. So I treat every allowed CDN as a possible way out.

The settings I changed

After all of the above, this is my baseline. Apply each line with sbx settings set <key> <value>, then restart the sbx daemon (sbx daemon restart) and the running sandboxes (sbx stop <name>, then sbx run --name <name>). Also check that sbx settings list shows SOURCE override. An environment variable would take precedence silently.

Setting Value Why
ssh.agentForwardingEnabled false No host SSH agent in sandboxes
browser.enabled false No opening URLs in my host browser past the egress policy
kit.requireSignature true Only kits signed by trusted signers
kit.allowedSources ["docker.io/sbx/","docker.io/docker/","dhi.io/"] docker.io/ alone allows any Hub user
sandbox.fuse false Otherwise /dev/fuse and SYS_ADMIN are exposed
model.server.enabled false Bundled local model server I don’t need
telemetry.disabled true Privacy

Clipboard access, Chrome control, Remote Control, remembered host commands and SSH auto-creation were already off on my machine. Keep platform.allowExperimentalFeatures on, because custom secrets and SSH depend on it.

Windows gotchas

Two Windows problems cost me some time.

sbx setup ssh wrote a broken Include line. The quotes were nested, so OpenSSH silently skipped the file and fell back to DNS: “Could not resolve hostname <name>.sbx”. Quoting each path separately fixed it:

# broken
Include "C:/Users/<you>/AppData/Local/DockerSandboxes/sandboxes/config/ssh/config "~/.ssh/sandboxes/local-sandboxes/config""
# working
Include "C:/Users/<you>/AppData/Local/DockerSandboxes/sandboxes/config/ssh/config" "C:/Users/<you>/.ssh/sandboxes/local-sandboxes/config"

Check the line again after every sbx setup ssh run. Also delete any Host <name>.sbx / HostName <name>.sbx block VS Code adds by itself.

JSON values and PowerShell. sbx settings set kit.allowedSources '["docker.io/sbx/", ...]' failed with “expected valid JSON”. Windows PowerShell 5.1 and PowerShell 7 before 7.2 strip the inner double quotes, so escape them as \". Check your version with $PSVersionTable.PSVersion.

What about GPUs?

If your agent needs a GPU, the options shrink fast. sbx GPU passthrough is experimental and uses VFIO, so it runs only on x86_64 Linux hosts. The sandbox gets the whole card, and the host loses it while the sandbox runs. WSL doesn’t help, because it shares the GPU through paravirtualization (/dev/dxg) rather than real PCIe passthrough.

Most alternatives are CPU-only too. E2B and microsandbox have no GPU support, largely because Firecracker-style microVMs don’t do passthrough. What does work:

  • Full VMs with passthrough: Proxmox, Incus or Kata Containers. You give one whole card to one VM.
  • gVisor with --nvproxy. It lets several containers share a GPU, but only for CUDA, only on supported cards and drivers, and the GPU itself is isolated only by the driver and the hardware.
  • Cloud GPU sandboxes like Daytona or Modal, if you’re fine with your code leaving your machine.

My plan is to not give agents a GPU at all. They write the training code and the job script in the sandbox. I review it and run it on a dedicated GPU host.

If I started over tomorrow

This is the order I’d do it in:

  1. Apply the settings baseline and restart the daemon.
  2. Remove any stored GitHub token (sbx secret ls, sbx secret rm -g github).
  3. Add Host *.sbx / ForwardAgent no to the SSH config and turn off VS Code agent forwarding.
  4. Create every sandbox from an explicit project folder, in clone or worktree mode where possible, with :ro on anything sensitive.
  5. Store API keys as custom secrets with --sandbox, and allow only their hosts, also with --sandbox.
  6. Deny the kit-provided hosts I don’t use.
  7. Run the socket loop and curl https://api.github.com/user (expect 401) inside the sandbox before letting the agent loose.

sbx gets the hard part right: a real VM boundary and a proxy that keeps keys out of the sandbox. What’s left is switching off the conveniences, one by one, and then checking that they stay off. The defaults assume you trust the agent. I don’t, at least not yet.

Still learning

I’m not done with this. My setup is the result of a few evenings, not of a security audit, and I’m sure there are doors I haven’t found yet. sbx also changes quickly. Several of the features I rely on are experimental, and some of the defaults above may look different in the next release. So I keep checking: sbx policy log after a new kit, the socket loop after a VS Code update, sbx settings list after an sbx upgrade. If you know a door I missed, or a better way to close one, please open an issue on this website’s GitHub repository. I’ll update the post.

Further reading

© 2026 Julius Aka. All rights reserved. Impressum