ai newsDi., 1. Dez.
EilmeldungThe Model Proposes, Your Code Disposes: A Tool-Calling Agent Loop for Android with Gemini Nano

Give Your AI Agent a Permission Slip: Least Privilege with Docker Sandbox Kits

Tested on macOS 27.0.1 with sbx 0.54.1. The credential-injection step after approval follows Docker's documentation. You ask your coding agent to fix a failing test. While it works, it can also call any API your tokens reach, and push to any repo you can push to. Nobody decided that. It's just what

dev.toSonntag 16:44 · 29.11.7 Min. Lesezeit
Bild: dev.to

Tested on macOS 27.0.1 with sbx 0.54.1. The credential-injection step after approval follows Docker's documentation.

You ask your coding agent to fix a failing test. While it works, it can also call any API your tokens reach, and push to any repo you can push to. Nobody decided that. It's just what "runs as you" means.

A sandbox helps. The previous post on Docker Sandboxes covered how: the agent gets its own microVM, and the network goes through a proxy on your machine. But someone still has to decide which doors in that wall are open, and for which agent.

That's what Docker Sandbox Kits are for. A Kit is a permission slip that ships with the agent. We'll write a small one, stack it with another, and see which rules survive.

An agent's permissions usually live in someone's head or a wiki page, not next to the agent itself.

So every team re-decides the same things. Can it reach GitHub? Which token does it get? And the answers drift: the agent image gets updated and the rules don't, or the other way around.

Docker's pitch is to put the rules inside the thing you ship. In their words, "Containers made software portable. Kits make authority portable." ( Docker ). That's a marketing line, but the idea behind it is sound: the rules should travel with the agent.

A Kit is an ordinary container image (an OCI image) with one extra thing: a short list of what the agent is asking to be allowed to do. That list sits in the image's metadata, so when you pin the image, you pin the permissions with it ( spec blog ).

Each permission is a typed entry called a capability, like network-policy@2 or credential@1. The @2 is a version, so a capability can change without breaking older Kits.

One rule matters more than the rest: a Kit only asks. The host decides. If a Kit requires something the host won't give, the sandbox doesn't start. If it marks a request optional, the host can skip it and the sandbox still runs ( spec ).

Here's the scenario. Your agent needs to read from one API, httpbin.org (a free test API). It should never delete anything there. And it gets a token it can use but can't see.

Make a scratch folder and cd into it. Everything below runs from there. Inside it, create a folder called httpbin-readonly with one file, httpbin-readonly/httpbin-readonly.yaml:

# syntax=docker/sandbox-kit:3 schemaVersion: "3" kind: mixin displayName: httpbin read-only description: Read from httpbin.org. Never delete. capabilities: - type: com.docker.sandbox/network-policy@2 config: runtime: allow: - hosts: [ httpbin.org ] methods: [ GET, HEAD ] deny: - hosts: [ httpbin.org ] methods: [ DELETE ] - type: com.docker.sandbox/credential@1 optional: true config: service: httpbin phase: runtime apiKey: name: HTTPBIN_TOKEN proxyManaged: true inject: - { domain: httpbin.org, header: Authorization, format: "Bearer %s" } Enter fullscreen mode Exit fullscreen mode Read it top to bottom, like a permission slip:

This is a declaration-only mixin. There's no Dockerfile, because it doesn't install anything. It only adds rules, and sbx builds the folder into a Kit when it creates the sandbox.

You need the sbx CLI, version 0.45.0 or newer, because that's when local sandboxes started enforcing these capabilities (the previous post covers the install). Check with sbx version.

Store a dummy secret first, so the credential request has something to point at:

# on your machine, not in the sandbox sbx secret set httpbin # paste any test value, e.g. test-123 Enter fullscreen mode Exit fullscreen mode Saved secret httpbin (global) Enter fullscreen mode Exit fullscreen mode Then validate the Kit and start a sandbox with it:

# on your machine sbx kit validate./httpbin-readonly sbx run shell --kit./httpbin-readonly. Enter fullscreen mode Exit fullscreen mode Before the sandbox starts, sbx shows you what the Kit is asking for and waits:

This kit wants to use these credentials: httpbin: API key sent to httpbin.org (stored) Approve these credentials? 1. Approve all 2. Review each 3. No start without them Choice [1-3, default 3]: Enter fullscreen mode Exit fullscreen mode This is the "a Kit only asks, the host decides" rule in action, and the safe answer is the default. Press Enter (no) for this first run. sbx says so plainly: credential not sent: no binding authorizes this service.

shell is one of the built-in agents: a workload Kit from Docker ( docker.io/sbx/shell ) that just gives you a shell, which is handy for testing rules without an agent in the way. --kit adds your mixin on top, and the final. is the folder to mount as the workspace. Kits apply when a sandbox is created, so if you change the YAML, start a new sandbox.

You're now in the sandbox shell. Try these:

# inside the sandbox echo "TOKEN=$HTTPBIN_TOKEN" for m in GET POST PUT DELETE; do printf "%-6s /anything/x -> " $m curl -s -o /dev/null -w "%{http_code}\n" -X $m https://httpbin.org/anything/x done printf "GET example.com -> "; curl -s -o /dev/null -w "%{http_code}\n" https://example.com curl -s https://httpbin.org/headers | grep -i authorization || echo "no Authorization header seen" Enter fullscreen mode Exit fullscreen mode Tested with sbx 0.54.1 on macOS:

TOKEN=proxy-managed GET /anything/x -> 200 POST /anything/x -> 403 PUT /anything/x -> 403 DELETE /anything/x -> 403 GET example.com -> 403 no Authorization header seen Enter fullscreen mode Exit fullscreen mode Line by line: the agent sees a placeholder, not your secret. Reads go through. Writes and deletes are blocked by the proxy with a 403. example.com is blocked by the sandbox's default policy, since nobody allowed it. And because you declined the credential, nothing was added to the request. If you choose 1 instead, Docker's docs say the proxy attaches the stored secret to httpbin.org requests, while echo inside the sandbox still prints proxy-managed ( Kit reference ).

Kits are meant to stack. Your security team ships one mixin, your platform team ships another, you add yours. So what happens when they disagree?

Say the platform team ships a broad Kit that allows httpbin.org for every method. Next to your first folder, create team-httpbin/team-httpbin.yaml:

# syntax=docker/sandbox-kit:3 schemaVersion: "3" kind: mixin displayName: team httpbin description: Platform team default. Allows httpbin.org for every method. capabilities: - type: com.docker.sandbox/network-policy@2 config: runtime: allow: - hosts: [ httpbin.org ] Enter fullscreen mode Exit fullscreen mode Exit the first sandbox, remove it ( sbx ls shows its name, which is shell- plus your folder name), and start a new one with both Kits:

# on your machine sbx rm shell-examples # asks y/N; this can't be undone sbx run shell --kit./httpbin-readonly --kit./team-httpbin. Enter fullscreen mode Exit fullscreen mode The spec has two rules for this ( spec ):

Run the same checks again, plus a DELETE on a different path. Tested with sbx 0.54.1 on macOS:

GET /anything/x -> 200 POST /anything/x -> 200 PUT /anything/x -> 200 DELETE /anything/x -> 403 DELETE /delete -> 403 GET example.com -> 403 Enter fullscreen mode Exit fullscreen mode POST and PUT now go through: your "GET only" didn't survive the merge. DELETE is still blocked on every path, because that one was a deny. And example.com stays blocked, because neither Kit asked for it.

Takeaway: if something must never happen, write it as a deny. A narrow allow can quietly disappear when someone stacks a broader one on top.

If you work in identity and access management, a lot of Kit design will look familiar. The comparisons are useful, as long as you know where each one stops.

The threats these map to are the ones identity people already worry about: an agent that over-reaches after a prompt injection (a confused deputy acting with your reach), a secret walking out the door, and permissions drifting wider as more pieces get composed.

The approval row deserves a closer look. The host keeps a record of exactly what it granted, which the spec calls the permission surface. If a new version of a Kit asks for more, like a new host, a removed deny or a new credential, the host stops and asks again. If it asks for the same or less, it can update quietly ( spec ).

Kits are new, so it's worth being clear about what they don't do yet:

A Kit won't stop an agent from making a mistake. It decides how far that mistake can reach.

Anoop Gopi is a Docker Captain. Views are his own and not Docker's.

Quelle: dev.to (dev.to). Original öffnen