sandbox-broker GitHub

way out 3 of 3

Capabilities

A capability is one named thing the host will do for a sandbox: fetch this repository, open a pull request, search my notes. The sandbox asks; a process on the host called the gateway decides, and does it with a credential the sandbox never holds.

The idea: a menu, a grant, a call

You write a menu: every operation any sandbox could ever ask for, each with a ceiling on how often and how much. You give an agent grants: which entries of the menu its sandboxes hold, narrowed to particular repositories or tighter limits. A sandbox then makes calls, and for each one the gateway answers three questions and no others.

The path of a capability call A process in the guest calls a local socket. On the host the gateway checks who is calling, whether they may ask this, and whether they have asked too much. A call that passes goes to a tool of yours, or to an API with the gateway's credential attached. IN THE GUEST any process curl, git, your agent's code /run/sb/cap.sock HTTP ON THE HOST · THE GATEWAY Who is calling? the kernel's word for the connection, never the caller's May they ask this? the menu, then the sandbox's grant and its scope Have they asked too much? in flight, this minute, today, and the sizes a tool of yours told who is calling; holds its own keys an API or a code host the gateway's credential attached
A call that fails any question is refused on the host. Nothing has been sent anywhere by then, and no token has been minted for it.

Two consequences are meant, and worth knowing before you design a menu:

  • The gateway tells sandboxes apart, not processes inside one. Everything running in a sandbox can use that sandbox's grants. Code that must not spend a grant runs in a sandbox that has none.
  • There is no grant finer than a menu entry. Reading and writing are two entries, each with its own limits. To hand out less, write a smaller entry.

Calling one, from inside a sandbox

A sandbox with grants has a Unix socket at $SB_CAP_SOCK. It speaks plain HTTP/1.1, so anything that can make a request can use it. There is nothing to authenticate with: the sandbox's identity is fixed outside it.

Ask what you hold

GET /_grants lists the sandbox's capabilities, how to call each, its limits and what has been used today. It is a good first thing to show a model: the answer is the tool list.

curl --unix-socket "$SB_CAP_SOCK" http://cap/_grants
{"caller": "vm", "agent": "mybot",
 "sandbox": "sw-mybot-1", "session": "s-91",
 "capabilities": {
   "notes.read": {
     "kind": "backend",
     "description": "Read this workspace's notes: …",
     "call": "/call/notes.read",
     "methods": ["GET"], "paths": ["/notes"], "query": ["q"],
     "limits": {"per_day": 2000, "per_minute": 60, "concurrent": 4, …},
     "used_today": 12, "scope": {}}}}

Make a call

Every call is /call/<capability>/<rest>. What the rest may be is the menu's to say.

curl --unix-socket "$SB_CAP_SOCK" \
  http://cap/call/notes.read/notes/today

Git needs no special handling

The guest's image carries a Git remote helper. A cap:: remote fetches through git.fetch and pushes through git.push.

git clone cap::github/acme/web
git clone --depth 1 cap::github/acme/web
git push origin HEAD:bot/fix-123

When the answer is no

A refusal by the gateway carries a header, Capability-Refusal: <word>, and the body {"error": "<word>", "message": "…"}. The words are a closed list, so an agent can act on them. A tool's own answer never carries that header.

wordstatusmeaning
not_granted403The capability is not on the menu, or this sandbox does not hold it.
scope403A path, a repository or a branch outside what the grant reaches, or a pull request that was not made (or is not being opened) from the agent's own branches.
content422The request body says something the capability does not take: a key it does not list, a value that is a list or an object, a value the capability does not allow, or an @ where the menu asks for none. Change the body and try again.
bad_request400, 404, 405, 408, 415A method, a query or a path the entry does not take, or a path that is not in plain form (no %, no .., no //).
too_large413, 502A request body or an answer over its limit.
concurrency429Too many of this capability's calls in flight. Try again shortly.
rate_limit429The minute is used up.
quota429The day is used up.
revoked403The grant was taken away while the call was being made.
upstream_error, upstream_timeout502, 504The tool or the API behind the capability failed or did not answer in time.

The four kinds

A menu entry has a kind. The kind says who carries the call out and who holds the credential.

kindwhat it iswho decides what
backend A call to a tool of yours: an HTTP server on a Unix socket of the host. The gateway checks the method, the path prefix, the sizes and the counts, and tells the tool which sandbox is calling. What the call means, and any credential it needs, are the tool's.
http_route One operation of an HTTP API: a method and a path template such as /repos/{owner}/{repo}/pulls. The gateway matches the path segment for segment, passes only the headers you list, and attaches its own credential: a static secret, or a GitHub App token for the repository in the path.
git_fetch Clone and fetch from one repository. The gateway serves Git's fetch protocol for the repository named, with a read-only token minted for it alone.
git_push Push to one repository, under a branch policy. The gateway reads the whole push first and checks every ref it would change. One ref outside the policy refuses the push, and none of it reaches the code host.
A menu of backend entries holds no secret and reaches no network. The other three kinds are what make the gateway the one place on the host that holds upstream credentials.

The menu is the gateway's config, /etc/sb-cap/config.toml. Every table refuses a key it does not know, and sb-cap --check-config checks every rule at once without starting anything. These examples are from deploy/sb-cap.toml.

A tool on this host

An upstream says where calls go. A capability says which calls. Paths match on whole segments: /notes admits /notes/x and never /notes-private. A query is refused unless its keys are listed.

[upstreams.notes]
kind = "unix"
socket = "/run/example-tool/cap.sock"
timeout_secs = 30

[capabilities."notes.read"]
kind = "backend"
upstream = "notes"
description = "Read this workspace's notes: GET /call/notes.read/notes/<name>"
methods = ["GET"]
allow_prefixes = ["/notes"]
allow_query_keys = ["q"]
ceiling = { per_day = 2000, per_minute = 60, concurrent = 4, body_max_bytes = 1024, response_max_bytes = 1048576 }

GitHub, as an App

The gateway holds the App's private key. For each call it mints a token for the one repository the call names, with exactly the entry's permissions.

Permissions are an allowlist in the code: contents, metadata, issues, pull_requests, and read-only checks, statuses and actions. Nothing that can change what CI runs, read a secret or add a webhook can be asked for.

Which repositories the App can touch at all is where you install it. That is the outer wall.

[upstreams.github]
kind = "github_app"
app_id = 123456
installations = { "acme" = 98765432 }
private_key_file = "/etc/sb-cap/keys/github-app.pem"

[capabilities."git.fetch"]
kind = "git_fetch"
upstream = "github"
permissions = { contents = "read" }
ceiling = { per_day = 200, per_minute = 20, concurrent = 4, body_max_bytes = 2097152, response_max_bytes = 268435456 }

[capabilities."git.push"]
kind = "git_push"
upstream = "github"
permissions = { contents = "write" }
branch_prefix = "bot/"
allow_update_existing = true
ceiling = { per_day = 100, per_minute = 10, concurrent = 2, pack_max_bytes = 16777216, response_max_bytes = 1048576 }

What a push may write

keymeaning
branch_prefixRequired. A push may write refs/heads/<prefix>… and nothing else. There is no push to any branch.
protected_refsRefs never written, whatever else allows them. Default: main and master.
allow_update_existingWhether a branch that exists may be moved. Default: no, a push may only create.
allow_deleteWhether a branch may be deleted. Default: no.
allow_tags, tag_prefixWhether tags may be written, and under which prefix. Default: no tags.

One operation of an API

A route is a method and a path template. A call's path must match it segment for segment; a {placeholder} takes one plain segment. The caller's headers go on only if listed, and never Authorization or Cookie: the gateway attaches its own.

For any other API, an http upstream attaches a static secret read from a file.

[capabilities."github.pr"]
kind = "http_route"
upstream = "github"
permissions = { pull_requests = "write", contents = "read" }
methods = ["POST"]
path_template = "/repos/{owner}/{repo}/pulls"
github_owner_placeholder = "owner"
github_repo_placeholder = "repo"
allow_headers = ["content-type", "accept", "x-github-api-version"]
ceiling = { per_day = 50, per_minute = 5, concurrent = 2, body_max_bytes = 65536, response_max_bytes = 1048576 }

[upstreams.example-api]
kind = "http"
base = "https://api.example.org/v1"
auth = { kind = "bearer_file", file = "/etc/sb-cap/keys/example.token" }

Granting

The menu says what exists. A grant gives one entry to one agent's sandboxes, and can only make it smaller.

In the broker's config

A grant has a scope and limits. For the GitHub kinds the scope must name the repositories: a list of owner/repo, or a whole owner as owner/*. A push's grant may also tighten the branch policy.

Limits may sit under the menu's ceiling. The gateway refuses a grant whose limit is above it: never clamped, never ignored. A misspelt key refuses the grant the same way, so a constraint is never silently off.

[agents.mybot]
grant_sets.reader = ["git.fetch"]
grant_sets.author = ["git.fetch", "git.push", "github.pr"]
default_grant_set = "reader"

[agents.mybot.grants."git.fetch"]
scope = { repos = ["acme/*"] }

[agents.mybot.grants."git.push"]
scope = { repos = ["acme/web"], branch_prefix = "bot/mybot/" }
limits = { per_day = 20 }

[agents.mybot.grants."github.pr"]
scope = { repos = ["acme/web"] }

Per sandbox, by name

Your tooling picks which of the agent's grants a sandbox holds when it creates it, and can change them while it runs. It chooses by name among what the config holds. It can never write a scope or a limit of its own.

Depending on the agent's setting, a running sandbox's grants may only shrink, or may switch between the agent's named sets.

b -X POST http://broker/v1/sandboxes \
  -d '{"grant_set": "author"}'

b -X PUT http://broker/v1/sandboxes/sw-mybot-1/grants \
  -d '{"grants": ["git.fetch"]}'

Taking them away

Dropping a grant ends the calls that were using it. They are cut mid-stream, not left to finish. An operator can also revoke a sandbox from outside the agent: its network goes to none and its grants to nothing, and that sandbox can never be widened again.

sandbox-broker control ls
sandbox-broker control revoke sw-mybot-1

A tool of your own

A tool is an HTTP/1.1 server on a Unix socket, in any language, in any repository. scripts/cap_tool.py is a complete one in a page. Adding one is a menu entry and a grant; nothing in the broker, the runner or the gateway changes.

  1. Admit the gateway alone. Check the peer's uid on every connection. That check is what makes the headers worth believing.
  2. Read who is calling from the headers, never from the request's content.
  3. Decide what this sandbox may touch. The gateway has checked the grant, the method, the path prefix, the sizes and the counts. The meaning is yours. A tool that decides nothing by who is calling gives every holder the same reach.
  4. Be a leaf. Answer with a length or chunked, stay bounded, and never call back into the sandbox that called you.
header the gateway setsvalue
Capability-Namethe capability called
Capability-Agentthe agent
Capability-Callervm, or host for an agent on the host
Capability-Sandboxthe sandbox's name
Capability-Sessionits current session
Capability-Scopethe grant's scope, as JSON; yours to interpret

A sandbox cannot forge these. Its own Capability-* headers are stripped before the gateway, and one that arrived anyway would be refused. Its Authorization and Cookie headers never reach a tool either.

Limits and the record

limitcounted pernotes
concurrentsandbox and capabilityCalls in flight. Taken before a request body is read.
per_minutesandbox and capabilityA sliding 60 seconds.
per_dayagent and capabilityThe UTC day, kept in a database, so it survives a restart. Shared by the agent's sandboxes. A refused call spends none of it.
body_max_bytes, response_max_bytescallA request over its size is refused. An answer over its size is broken off, so the caller sees a failed response and never a short one that looks whole.

Every call also ends 300 seconds after it began. Each one is written to a private audit on the host: who called, which capability, the method and path, whether it was granted or which word refused it, the status and the sizes. Never a query, a header or a byte of a body. sb-cap audit prints it; Prometheus metrics count requests and refusals by agent and capability.

What to keep off the menu

The gateway bounds who may ask for what and how often. It does not understand what a request means. Four things follow.

  • A route's body is not read. The gateway judges a route's method, path and query. So a route is every operation the API serves at that method and path. One that posts a pull request review can also approve it. List a route only if every body it could carry is acceptable.
  • A push is code execution wherever CI runs on it. A push is judged by the refs it names, not by what the commits contain. Install the App only on repositories where a pushed branch runs nothing that holds a secret.
  • Free text is a way out for data, and a command where bots listen. A comment or a pull request body can carry anything the sandbox has read, and can say whatever a repository's chat-ops obey.
  • An upstream that echoes its credential hands it over. Answers go back as they are. An API with a debugging endpoint that reflects the Authorization header must not be on the menu.

The full list is in docs/cap.md, Known weaknesses, and on the security page.

Where it stands, December 2026. Every path on this page is tested end to end from a real guest under Firecracker, with a stand-in for GitHub that verifies each token request's signature. It was run against GitHub itself on 4 December 2026, from a real guest, for one private scratch repository. Setting up the App is in docs/cap.md.