box-exec-proxy
by so0k
README.md
# box-exec-proxy
A local MCP server that gives an agent Cloudflare's code-mode tools, `search` and `execute(code)`,
but runs the agent's script inside a [Strands Box](https://github.com/strands-agents/box) sandbox.
Every API request the script makes leaves through Box's egress gateway, where Cedar policies
(checked by Dogwood) decide each request on its own.
## The problem
A security officer has to say which Cloudflare API operations an agent may use. For example: read
the Worker list and its deployments, but never the Worker's logs, never SQL on the database, never
deploy or delete. Cloudflare's MCP server in code mode offers one generic tool, `execute(code)`,
and runs the script on Cloudflare's side. Box sees one tool call and none of the API requests
inside it. The officer can only allow `execute` or refuse it: everything or nothing.
This proxy keeps the same two tools and moves the script into the box. Each
`cloudflare.request(...)` or `fetch(...)` becomes a real HTTPS request that Box decides by host,
method and path, so the officer keeps control per API operation. The proxy is a convenience
tool, not a security component: Box is the sandbox and the enforcement point. The proxy holds
no policy, and inside a box it holds no real secret either, because Box's egress gateway adds the
token. Run outside a box, the proxy reads `CLOUDFLARE_API_TOKEN` from its environment and sends
that token itself.
## The request path
```text
agent (Claude Code)
| mcp:call exec-proxy/execute { code } decided by Box's MCP broker
exec proxy, in its own Box sandbox the script calls cloudflare.request(...)
| one HTTPS request per call
Box egress gateway http:request: host, method, path
| permitted: the real token is added refused: 403, never sent
api.cloudflare.com/client/v4/...
```
## Layout
| Path | What |
| --- | --- |
| `proxy/` | The MCP server. Node 22, no dependencies, JSON-RPC over stdio. |
| `test/` | Tests for the proxy and the policy kit, against local fake servers. No network. |
| `tools/fetch-spec.sh`, `tools/process-spec.js` | Download and process Cloudflare's OpenAPI description into `spec/` (git-ignored). |
| `tools/policy-gen/`, `kit/` | The policy kit: per-operation policy generated from an operator file. |
| `examples/` | A Box profile, the MCP server file for Claude Code, and the egress policy. |
| `sample-app/` | The Cloudflare Worker the demo operated on. |
## Quick start
You need Node 22 (the commands use [mise](https://mise.jdx.dev/)), `git` and `curl`.
```sh
git clone https://github.com/so0k/box-exec-proxy.git "$HOME/box-exec-proxy"
cd "$HOME/box-exec-proxy"
./tools/fetch-spec.sh
mise x node@22 -- npm test
```
`tools/fetch-spec.sh` downloads about 27 MB from a pinned release of
[cloudflare/forge](https://github.com/cloudflare/forge) and writes `spec/spec.json`. The `search`
tool reads that file. `npm test` also passes without it, but then it skips the kit scenario tests.
`SPEC_URL=latest ./tools/fetch-spec.sh` takes the newest release instead; the committed kit
policies may then no longer match it.
### Register it with Box
The files in `examples/` are the end state of Part 5 of the workshop. They assume the clone is at
`$HOME/box-exec-proxy`. Replace the placeholders first:
- In `examples/profile.toml`: the Node folder (`mise where node@22` prints yours) and the account
id `0123456789abcdef0123456789abcdef`.
- In `examples/api-read-only.dw`: the same account id, and `box-poc-workshop` if your Worker has
another name.
With `BOX_HOME` set as in the workshop, copy the profile and the policy into a profile folder,
and the MCP file into the project folder you run the agent from:
```sh
mkdir -p "$BOX_HOME/profiles/ws"
cp examples/profile.toml examples/api-read-only.dw "$BOX_HOME/profiles/ws/"
cp examples/exec-proxy.json <your-project-folder>/
box profile show ws --full
```
The profile reads `ANTHROPIC_API_KEY` and `CLOUDFLARE_API_TOKEN` from the shell that runs
`box run`. Neither the registration steps above nor the launch command below were run from this
repository; the workshop shows each step. The launch command, run from the project folder:
```sh
box run ws -- --bare --strict-mcp-config --mcp-config exec-proxy.json --tools "" \
--allowedTools mcp__exec-proxy --model claude-sonnet-5-5 --max-turns 10 --permission-mode manual
```
## Which Box build
Upstream Box is [strands-agents/box](https://github.com/strands-agents/box). The workshop ran on
one local build: upstream commit `c70fec5` plus an earlier round of a fix for MCP tool schemas
with shared definitions (`$defs`), built as an uncommitted diff. The branch
`bugfix/mcp-shared-definitions-workshop` of [so0k/box](https://github.com/so0k/box) holds a later
review round of the same fix on the same commit, so a build from it is not byte-identical to the
workshop's build, and the workshop was not run again on it. The branch
`bugfix/mcp-shared-definitions` carries the same fix on current upstream main. Release v0.3.0 and
upstream main do not have it yet.
- The fix matters for Part 4 of the workshop, Cloudflare's one-tool-per-operation catalog: 441 of
its 3,053 tools use those constructs, and without the fix Box refuses every call to that server.
- The exec proxy (act c) does not read that catalog, and its two tools have plain schemas. The
workshop measured act c on its own build described above, and also ran it on builds without this fix, among
them the older release box 0.1.8 (which uses a different profile format). It was not run on
release v0.3.0. The examples use the newer CLI's profile format (`$BOX_HOME`, `@box/base`).
## The policy kit
Hand-written path rules are easy to get wrong: Cedar's `like` wildcard `*` also matches `/`, and
a credential route permits every request to its host. The generator in `tools/policy-gen/`
reads an operator file (`kit/scenarios/<name>/operator.toml`) and the OpenAPI description, and
writes `policy.dw` (one allow-list plus deny rules with reasons) and `review.txt` (what the policy
does and what its self-check found). `mise x node@22 -- npm run kit` regenerates all six
scenarios. `test/kit-scenarios.test.js` checks that the committed files match the generator for
the pinned spec. The scenarios use the fake account id and a vendor MCP server named `vendor-cf`.
Their policies were not loaded into Box from this repository.
## The sample app
`sample-app/` is the app the demo agent operated: a workshop progress tracker and leaderboard.
It is one Worker (`box-poc-workshop`) with two Durable Objects (one per attendee session, one per
workshop board), a D1 session registry, a KV namespace of workshop content, and Workers Logs. The
logs hold attendee names and emails on purpose, so "the agent may not read the logs" is a real
control.
It is coupled to the TerraConstructs AWS workshop. `sample-app/tools/gen-content.mjs` generates
`sample-app/content/workshop.json` from that website's workshop pages, and CORS allows only
`https://terraconstructs.dev` (plus localhost in `wrangler dev`, and box hosts when `BOX_DOMAIN`
is set).
```sh
cd sample-app # offline tests: the Worker runs in local workerd, no network
mise x node@22 -- npm ci
mise x node@22 -- npm test
mise x node@22 -- npm run typecheck
```
### Deploy your own copy
Not run from this repository. With your own Cloudflare account and Node 22, from `sample-app/`,
the Worker ends up at `https://box-poc-workshop.<your-subdomain>.workers.dev`:
```sh
npx wrangler d1 create box-poc-workshop
npx wrangler kv namespace create box-poc-workshop-content
# put your account id, the D1 id and the KV id into wrangler.jsonc
npx wrangler d1 migrations apply box-poc-workshop --remote
npx wrangler kv key put workshop --path content/workshop.json --namespace-id <your-kv-id> --remote
npx wrangler secret put DASHBOARD_SECRET
npx wrangler deploy
```
`sample-app/scripts/` and `sample-app/infra/` are the scripts used for the demo deployment,
kept as a reference: macOS keychain based, OpenTofu through cdktn, not run from this repository.
They read your account id, workers.dev subdomain, bootstrap token id and token expiry
(`TOKEN_EXPIRES_ON`) from the environment.
## Learn it step by step
The workshop [Agent in a Box](https://so0k.github.io/agent-in-a-box/) builds this up from a first
Box profile to act c, with the decisions Box records at each step. Its Part 5 teaches this proxy.
## Status
A proof of concept and a reference, not a product. Interfaces may change.
## Licence and attribution
Apache License 2.0, see [LICENSE](LICENSE). `proxy/lib/spec.js` and `proxy/lib/truncate.js` are
ports of files from [cloudflare/mcp](https://github.com/cloudflare/mcp) (Apache-2.0); see
[NOTICE](NOTICE).
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues