Skip to content

Commit b62c42f

Browse files
authored
feat(sandbox): support policy discovery and restrictive defaults on sandbox containers (#84)
1 parent 2d56904 commit b62c42f

36 files changed

Lines changed: 854 additions & 229 deletions

File tree

‎.agents/skills/create-spike/SKILL.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ User says: "Allow sandbox egress to private IP space via networking policy"
289289
1. Problem is clear — no clarification needed
290290
2. Fire `principal-engineer-reviewer` to investigate:
291291
- Finds `is_internal_ip()` SSRF check in `proxy.rs` that blocks RFC 1918 addresses
292-
- Reads OPA policy evaluation pipeline in `opa.rs` and `dev-sandbox-policy.rego`
292+
- Reads OPA policy evaluation pipeline in `opa.rs` and `crates/navigator-sandbox/data/sandbox-policy.rego`
293293
- Reads proto definitions in `sandbox.proto` for `NetworkEndpoint`
294294
- Maps the 4-layer defense model: netns, seccomp, OPA, SSRF check
295295
- Reads `architecture/security-policy.md` and `architecture/sandbox.md`

‎.agents/skills/generate-sandbox-policy/SKILL.md‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ Key sections to reference:
170170
Also read the example policy for real-world patterns:
171171

172172
```
173-
Read dev-sandbox-policy.yaml
173+
Read deploy/docker/sandbox/dev-sandbox-policy.yaml
174174
```
175175

176176
## Step 4: Choose Policy Shape
@@ -355,8 +355,8 @@ The policy needs to go somewhere. Determine which mode applies:
355355

356356
| Signal | Mode |
357357
|--------|------|
358-
| User names an existing policy file (e.g., "add to dev-sandbox-policy.yaml") | **Update existing file** |
359-
| User says "update my policy", "add this to my policy file" | **Update existing file** — look for `dev-sandbox-policy.yaml` or ask which file |
358+
| User names an existing policy file (e.g., "add to deploy/docker/sandbox/dev-sandbox-policy.yaml") | **Update existing file** |
359+
| User says "update my policy", "add this to my policy file" | **Update existing file** — look for `deploy/docker/sandbox/dev-sandbox-policy.yaml` or ask which file |
360360
| User asks to modify an existing policy rule by name | **Update existing file** — edit the named policy in place |
361361
| User says "create a new policy file" or names a file that doesn't exist | **Create new file** |
362362
| No file context given | **Present only** — show the YAML and ask if the user wants it written to a file |
@@ -418,7 +418,7 @@ inference:
418418
419419
The `filesystem_policy`, `landlock`, `process`, and `inference` sections above are sensible defaults. Tell the user these are defaults and may need adjustment for their environment. The generated `network_policies` block is the primary output.
420420

421-
If the user provides a file path, write to it. Otherwise, suggest `dev-sandbox-policy.yaml` for local development or ask where to place it.
421+
If the user provides a file path, write to it. Otherwise, suggest `deploy/docker/sandbox/dev-sandbox-policy.yaml` for local development or ask where to place it.
422422

423423
### Mode C: Present Only (no file write)
424424

@@ -427,7 +427,7 @@ Show the generated policy YAML with:
427427
1. **Summary** — what the policy allows and denies, in plain language
428428
2. **The YAML** — the complete `network_policies` block, ready to paste
429429
3. **Integration guidance**:
430-
- For local dev: add to `dev-sandbox-policy.yaml` under `network_policies`
430+
- For local dev: add to `deploy/docker/sandbox/dev-sandbox-policy.yaml` under `network_policies`
431431
- For production: configure via the gateway
432432
4. **Caveats** — any assumptions made, anything the user should verify
433433

@@ -545,6 +545,6 @@ private_services:
545545
## Additional Resources
546546

547547
- Full policy schema: [architecture/security-policy.md](../../../architecture/security-policy.md)
548-
- Example policy file: [dev-sandbox-policy.yaml](../../../dev-sandbox-policy.yaml)
549-
- Rego evaluation rules: [dev-sandbox-policy.rego](../../../dev-sandbox-policy.rego)
548+
- Example policy file: [dev-sandbox-policy.yaml](../../../deploy/docker/sandbox/dev-sandbox-policy.yaml)
549+
- Rego evaluation rules: [sandbox-policy.rego](../../../crates/navigator-sandbox/data/sandbox-policy.rego)
550550
- For translation examples from real API docs, see [examples.md](examples.md)

‎.agents/skills/generate-sandbox-policy/examples.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -729,11 +729,11 @@ An exact IP is treated as `/32` — only that specific address is permitted.
729729

730730
### Example F1: Add a New Policy to an Existing File
731731

732-
**User**: "Add read-only access to api.github.com for curl to my dev-sandbox-policy.yaml"
732+
**User**: "Add read-only access to api.github.com for curl to my deploy/docker/sandbox/dev-sandbox-policy.yaml"
733733

734734
**Agent workflow**:
735735

736-
1. Read `dev-sandbox-policy.yaml`
736+
1. Read `deploy/docker/sandbox/dev-sandbox-policy.yaml`
737737
2. Check that no existing policy already covers `api.github.com:443` — if one does, warn about overlap
738738
3. Check that the key `github_readonly` doesn't already exist
739739
4. Insert the new policy under `network_policies`:
@@ -760,11 +760,11 @@ The agent uses `StrReplace` to insert after the last existing policy in the `net
760760

761761
### Example F2: Modify an Existing Policy (Add an Endpoint)
762762

763-
**User**: "Add sentry.io to the claude_code policy in dev-sandbox-policy.yaml"
763+
**User**: "Add sentry.io to the claude_code policy in deploy/docker/sandbox/dev-sandbox-policy.yaml"
764764

765765
**Agent workflow**:
766766

767-
1. Read `dev-sandbox-policy.yaml`
767+
1. Read `deploy/docker/sandbox/dev-sandbox-policy.yaml`
768768
2. Find the `claude_code` policy
769769
3. Check that `sentry.io:443` isn't already listed in its endpoints
770770
4. Add the new endpoint to the existing `endpoints` list:
@@ -878,11 +878,11 @@ The agent notes that `filesystem_policy`, `landlock`, `process`, and `inference`
878878

879879
### Example F5: Handle a Key Conflict
880880

881-
**User**: "Add an nvidia policy to dev-sandbox-policy.yaml"
881+
**User**: "Add an nvidia policy to deploy/docker/sandbox/dev-sandbox-policy.yaml"
882882

883883
**Agent workflow**:
884884

885-
1. Read `dev-sandbox-policy.yaml`
885+
1. Read `deploy/docker/sandbox/dev-sandbox-policy.yaml`
886886
2. Find that a policy key `nvidia` already exists
887887
3. **Ask the user**: "A policy named `nvidia` already exists. Do you want to replace it, add endpoints to it, or use a different name (e.g., `nvidia_inference_v2`)?"
888888
4. Proceed based on the user's answer

‎.claude/agent-memory/arch-doc-writer/MEMORY.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
- Naming convention: "gateway" in prose for the control plane component; code identifiers like `navigator-server` stay unchanged
2424

2525
## Key Patterns
26-
- OPA baked-in rules: `include_str!("../../../dev-sandbox-policy.rego")` in opa.rs
26+
- OPA baked-in rules: `include_str!("../data/sandbox-policy.rego")` in opa.rs
2727
- Policy loading: gRPC mode (NAVIGATOR_SANDBOX_ID + NAVIGATOR_ENDPOINT) or file mode (--policy-rules + --policy-data)
2828
- Provider env injection: both entrypoint process (tokio Command) and SSH shell (std Command)
2929
- Cluster bootstrap: `sandbox_create_with_bootstrap()` auto-deploys when no cluster exists (main.rs ~line 632)

‎Cargo.lock‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎architecture/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ The inference routing system transparently intercepts AI inference API calls fro
198198

199199
| Component | Location | Role |
200200
|---|---|---|
201-
| OPA `network_action` rule | `dev-sandbox-policy.rego` | Returns `inspect_for_inference` when no explicit policy match and inference routes exist |
201+
| OPA `network_action` rule | `crates/navigator-sandbox/data/sandbox-policy.rego` | Returns `inspect_for_inference` when no explicit policy match and inference routes exist |
202202
| Proxy interception | `crates/navigator-sandbox/src/proxy.rs` | TLS-terminates intercepted connections, parses HTTP, calls gateway |
203203
| Inference pattern detection | `crates/navigator-sandbox/src/l7/inference.rs` | Matches HTTP method + path against known inference API patterns |
204204
| gRPC forwarding | `crates/navigator-sandbox/src/grpc_client.rs` | Sends `ProxyInferenceRequest` to the gateway |

‎architecture/build-containers.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ All builds use mise tasks defined in `tasks/*.toml` (included from `mise.toml`).
338338
| `crates/navigator-core/*`, `crates/navigator-providers/*` | Gateway + sandbox rebuild |
339339
| `crates/navigator-router/*` | Gateway rebuild |
340340
| `crates/navigator-server/*`, `deploy/docker/Dockerfile.server` | Gateway rebuild |
341-
| `crates/navigator-sandbox/*`, `deploy/docker/sandbox/*`, `deploy/docker/openclaw-start.sh`, `python/*`, `pyproject.toml`, `uv.lock`, `dev-sandbox-policy.rego` | Sandbox rebuild |
341+
| `crates/navigator-sandbox/*`, `deploy/docker/sandbox/*`, `deploy/docker/openclaw-start.sh`, `python/*`, `pyproject.toml`, `uv.lock`, `crates/navigator-sandbox/data/sandbox-policy.rego` | Sandbox rebuild |
342342
| `deploy/helm/navigator/*` | Helm upgrade |
343343

344344
**Explicit target mode** (arguments: `server`, `sandbox`, `chart`, `all`): Rebuilds only the specified components.

‎architecture/inference-routing.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The inference routing system transparently intercepts AI inference API calls fro
2222
| `crates/navigator-sandbox/src/main.rs` | Sandbox binary CLI: `--inference-routes` / `NEMOCLAW_INFERENCE_ROUTES` flag definition |
2323
| `tasks/ci.toml` | `[sandbox]` task: mounts `inference-routes.yaml`, sets env vars for dev sandbox |
2424
| `inference-routes.yaml` | Default standalone routes for dev sandbox (NVIDIA API endpoint) |
25-
| `dev-sandbox-policy.rego` | `network_action` Rego rule -- tri-state decision logic |
25+
| `crates/navigator-sandbox/data/sandbox-policy.rego` | `network_action` Rego rule -- tri-state decision logic |
2626

2727
## Architecture Overview
2828

@@ -174,7 +174,7 @@ The `evaluate_network_action()` method evaluates `data.navigator.sandbox.network
174174

175175
### Rego rules
176176

177-
**File:** `dev-sandbox-policy.rego`
177+
**File:** `crates/navigator-sandbox/data/sandbox-policy.rego`
178178

179179
```rego
180180
default network_action := "deny"
@@ -567,8 +567,8 @@ The `create` and `update` commands perform protocol auto-detection when `--proto
567567

568568
Running `mise run cluster:sandbox` starts a standalone sandbox container with inference routing pre-configured. The task mounts three files into the container:
569569

570-
- `dev-sandbox-policy.rego` as `/var/navigator/policy.rego`
571-
- `dev-sandbox-policy.yaml` as `/var/navigator/data.yaml`
570+
- `crates/navigator-sandbox/data/sandbox-policy.rego` as `/var/navigator/policy.rego`
571+
- `deploy/docker/sandbox/dev-sandbox-policy.yaml` as `/var/navigator/data.yaml`
572572
- `inference-routes.yaml` as `/var/navigator/inference-routes.yaml`
573573

574574
The container receives `NEMOCLAW_INFERENCE_ROUTES=/var/navigator/inference-routes.yaml` to enable standalone inference routing. `NVIDIA_API_KEY` is always forwarded from the host environment (empty string if unset).

‎architecture/sandbox.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ The OPA engine lives in `crates/navigator-sandbox/src/opa.rs` and uses the `rego
191191

192192
### Baked-in rules
193193

194-
The Rego rules are compiled into the binary via `include_str!("../../../dev-sandbox-policy.rego")`. The package is `navigator.sandbox`. Key rules:
194+
The Rego rules are compiled into the binary via `include_str!("../data/sandbox-policy.rego")`. The package is `navigator.sandbox`. Key rules:
195195

196196
| Rule | Type | Purpose |
197197
|------|------|---------|

‎architecture/security-policy.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Provide a Rego rules file and a YAML data file via CLI flags or environment vari
1717

1818
```bash
1919
navigator-sandbox \
20-
--policy-rules dev-sandbox-policy.rego \
20+
--policy-rules sandbox-policy.rego \
2121
--policy-data dev-sandbox-policy.yaml \
2222
-- /bin/bash
2323
```
@@ -45,7 +45,7 @@ navigator-sandbox \
4545
| `--sandbox-id` | `NEMOCLAW_SANDBOX_ID` | Sandbox ID for policy lookup |
4646
| `--nemoclaw-endpoint` | `NEMOCLAW_ENDPOINT` | Gateway gRPC endpoint |
4747

48-
The gateway returns a `SandboxPolicy` protobuf message (defined in `proto/sandbox.proto`). The sandbox supervisor converts this proto into JSON, validates L7 config, expands presets, and loads it into the OPA engine using baked-in Rego rules (`dev-sandbox-policy.rego` compiled via `include_str!`). See `crates/navigator-sandbox/src/opa.rs` -- `OpaEngine::from_proto()`.
48+
The gateway returns a `SandboxPolicy` protobuf message (defined in `proto/sandbox.proto`). The sandbox supervisor converts this proto into JSON, validates L7 config, expands presets, and loads it into the OPA engine using baked-in Rego rules (`sandbox-policy.rego` compiled via `include_str!`). See `crates/navigator-sandbox/src/opa.rs` -- `OpaEngine::from_proto()`.
4949

5050
### Policy Loading Sequence
5151

@@ -421,7 +421,7 @@ Each endpoint defines a network destination and, optionally, L7 inspection behav
421421
| ------ | -------- | -------- | ------------------------------------------------------------------ |
422422
| `path` | `string` | Yes | Filesystem path of the binary. Supports glob patterns (`*`, `**`). |
423423

424-
**Binary identity matching** is evaluated in the Rego rules (`dev-sandbox-policy.rego`) using four strategies, tried in order:
424+
**Binary identity matching** is evaluated in the Rego rules (`sandbox-policy.rego`) using four strategies, tried in order:
425425

426426
1. **Direct path match** -- `exec.path == binary.path`
427427
2. **Ancestor match** -- any entry in `exec.ancestors` matches `binary.path`
@@ -450,7 +450,7 @@ rules:
450450
| `path` | `string` | URL path glob pattern: `**` matches everything, otherwise `glob.match` with `/` delimiter. |
451451
| `command` | `string` | SQL command: `SELECT`, `INSERT`, `UPDATE`, `DELETE`, or `*` (any). Case-insensitive matching. For `protocol: sql` endpoints. |
452452

453-
Method and command fields use `*` as wildcard for "any". Path patterns use `**` for "match everything" and standard glob patterns with `/` as a delimiter otherwise. See `dev-sandbox-policy.rego` -- `method_matches()`, `path_matches()`, `command_matches()`.
453+
Method and command fields use `*` as wildcard for "any". Path patterns use `**` for "match everything" and standard glob patterns with `/` as a delimiter otherwise. See `sandbox-policy.rego` -- `method_matches()`, `path_matches()`, `command_matches()`.
454454

455455
#### Access Presets
456456

@@ -524,7 +524,7 @@ flowchart LR
524524

525525
This is the single most important behavioral trigger in the policy language. An endpoint with no `protocol` field passes traffic opaquely after the L4 (CONNECT) check. Adding `protocol: rest` activates per-request HTTP parsing and policy evaluation inside the proxy.
526526

527-
**Implementation path**: After L4 CONNECT is allowed, the proxy calls `query_l7_config()` which evaluates the Rego rule `data.navigator.sandbox.matched_endpoint_config`. This rule only matches endpoints that have a `protocol` field set (see `dev-sandbox-policy.rego` line `ep.protocol`). If a config is returned, the proxy enters `relay_with_inspection()` instead of `copy_bidirectional()`. See `crates/navigator-sandbox/src/proxy.rs` -- `handle_tcp_connection()`.
527+
**Implementation path**: After L4 CONNECT is allowed, the proxy calls `query_l7_config()` which evaluates the Rego rule `data.navigator.sandbox.matched_endpoint_config`. This rule only matches endpoints that have a `protocol` field set (see `sandbox-policy.rego` line `ep.protocol`). If a config is returned, the proxy enters `relay_with_inspection()` instead of `copy_bidirectional()`. See `crates/navigator-sandbox/src/proxy.rs` -- `handle_tcp_connection()`.
528528

529529
**Validation requirement**: When `protocol` is set, either `rules` or `access` must also be present. An endpoint with `protocol` but no rules/access is rejected at validation time because it would deny all traffic (no allow rules means nothing matches). See `crates/navigator-sandbox/src/l7/mod.rs` -- `validate_l7_policies()`.
530530

@@ -1055,7 +1055,7 @@ The OPA engine evaluates two categories of rules:
10551055
| `allow_request` | `input.network.*`, `input.exec.*`, `input.request.method`, `input.request.path` | `true` if the request matches any rule in the matched endpoint |
10561056
| `request_deny_reason` | Same input | Human-readable deny message |
10571057

1058-
See `dev-sandbox-policy.rego` for the full Rego implementation.
1058+
See `sandbox-policy.rego` for the full Rego implementation.
10591059

10601060
---
10611061

0 commit comments

Comments
 (0)