Skip to content

Commit 3a1468a

Browse files
committed
feat(cli): check sandbox prints one row per path with its reason tag, the Git protection state, and a skip where a probe does not apply
- Each policy path has one row per enforcement scope: access marker, a `sys`, `net` or `tool` tag or a role annotation, the full path; the five granted device nodes and each network-support file get their own rows; enforcement is stated once per section. - The Git row shows the configured `sandbox.protect_git` and the effective protection, with the reason when they differ. - The network probe reads `[SKIP]` under `partial` and `none`, which have no network namespace; `SandboxReport` carries PASS, FAIL or SKIP. - Colour follows `NO_COLOR` and a non-TTY stdout; long annotations wrap with a hanging indent.
1 parent 4b0d2eb commit 3a1468a

11 files changed

Lines changed: 955 additions & 412 deletions

File tree

‎docs/security.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,11 @@ Outside its control: the kernel, the agent6 binary, the provider endpoints.
7272

7373
## Defense layers
7474

75-
`agent6 check sandbox` prints a table for the file tools and one for the jailed commands: a root row, a home-directory row and a row per path, a parent before its children.
75+
`agent6 check sandbox` prints separate filesystem enforcement sections for the file tools and jailed commands, with one row per policy path in each scope, parents before children and root and home boundary rows where no grant covers them.
76+
The `rw`, `ro` and `--` markers show access; `sys`, `net` and `tool` tags show purpose, and annotations combine discovery and configuration details.
77+
The Git row shows configured and effective protection, and each granted device has its own row.
7678
It also prints a line per MCP server, the network, the approval mode and the secrets posture, then runs the jail probes.
79+
The network probe reads `[SKIP]` under `partial` and `none`, which have no network namespace.
7780

7881
### 1. Trust boundary
7982

‎pyproject.toml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ banned-from = [
351351
"agent6.ui.acp.updates",
352352
"agent6.ui.btw",
353353
"agent6.ui.cli._ask",
354+
"agent6.ui.cli._check_render",
354355
"agent6.ui.cli._check_sandbox",
355356
"agent6.ui.cli._common",
356357
"agent6.ui.cli._compare",
@@ -366,6 +367,7 @@ banned-from = [
366367
"agent6.ui.cli._repl",
367368
"agent6.ui.cli._review_args",
368369
"agent6.ui.cli._run_args",
370+
"agent6.ui.cli._sandbox_paths",
369371
"agent6.ui.cli._session_prompt",
370372
"agent6.ui.cli._sessions_args",
371373
"agent6.ui.cli._skills_args",

‎src/agent6/kinds.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,12 @@ class SandboxReport:
342342
343343
Attributes:
344344
name: The test's name.
345-
ok: Whether it passed.
345+
status: PASS, FAIL or SKIP when the probe does not apply.
346346
detail: What it found.
347347
"""
348348

349349
name: str
350-
ok: bool
350+
status: Literal["PASS", "FAIL", "SKIP"]
351351
detail: str
352352

353353

‎src/agent6/sandbox/tool_paths.py‎

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,17 @@ class ToolMount:
5757
5858
Attributes:
5959
path: The dir, at its real location.
60-
why: Why the jail mounts it: a bin dir on the jail's PATH, the tool that links into
61-
it, or uv's interpreters.
60+
on_path: The directory is on the jail's PATH.
61+
links: Symlink sources whose targets live in this directory.
62+
runtimes: Established runtime dependencies supplied by this directory.
6263
"""
6364

6465
path: pathlib.Path
65-
why: str
66+
on_path: bool = False
67+
links: tuple[pathlib.Path, ...] = ()
68+
runtimes: tuple[str, ...] = ()
6669

6770

68-
_ON_PATH = "on the jail's PATH"
6971
_UV_PYTHONS = "uv-managed interpreters"
7072

7173

@@ -77,15 +79,16 @@ def operator_tool_mounts() -> tuple[ToolMount, ...]:
7779
symlink resolves to, also needs the mount.
7880
7981
Returns:
80-
The mounts. A dir mounted for several reasons gets one `why`: the jail's PATH,
81-
else uv's interpreters, else its first link with a count of the rest.
82+
The mounts, with every discovery source retained for each directory.
8283
"""
84+
on_path: set[pathlib.Path] = set()
85+
links: dict[pathlib.Path, list[pathlib.Path]] = {}
8386
whys: dict[pathlib.Path, list[str]] = {}
8487
for d in _tool_bin_dirs():
8588
if not d.is_dir():
8689
continue
8790
if not _under_system_root(d) and not _never_mounted(d):
88-
whys.setdefault(d, []).append(_ON_PATH)
91+
on_path.add(d)
8992
try:
9093
entries = list(d.iterdir())
9194
except OSError:
@@ -98,7 +101,7 @@ def operator_tool_mounts() -> tuple[ToolMount, ...]:
98101
except OSError:
99102
continue
100103
if real.is_file() and not _under_system_root(real) and not _never_mounted(real.parent):
101-
whys.setdefault(real.parent, []).append(f"{entry} links here")
104+
links.setdefault(real.parent, []).append(entry)
102105
# uv-managed CPython lives under XDG data; without this mount an in-jail `uv run` sees the
103106
# venv's interpreter missing and recreates the operator's .venv. A mount, never a PATH entry.
104107
data_home = pathlib.Path(
@@ -107,16 +110,10 @@ def operator_tool_mounts() -> tuple[ToolMount, ...]:
107110
uv_pythons = data_home / "uv" / "python"
108111
if uv_pythons.is_dir():
109112
whys.setdefault(uv_pythons, []).append(_UV_PYTHONS)
110-
out: list[ToolMount] = []
111-
for path in sorted(whys):
112-
reasons = whys[path]
113-
if _ON_PATH in reasons or _UV_PYTHONS in reasons:
114-
why = _ON_PATH if _ON_PATH in reasons else _UV_PYTHONS
115-
else:
116-
more = f", {len(reasons) - 1} more" if len(reasons) > 1 else ""
117-
why = f"{reasons[0]}{more}"
118-
out.append(ToolMount(path, why))
119-
return tuple(out)
113+
return tuple(
114+
ToolMount(path, path in on_path, tuple(links.get(path, ())), tuple(whys.get(path, ())))
115+
for path in sorted(on_path | links.keys() | whys.keys())
116+
)
120117

121118

122119
def operator_tool_paths() -> tuple[str, tuple[pathlib.Path, ...]]:

‎src/agent6/ui/cli/_check_render.py‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# Copyright 2026 Eric Lesiuta
3+
"""Render check output with monochrome paths and hanging annotations."""
4+
5+
from __future__ import annotations
6+
7+
import re
8+
import shutil
9+
import sys
10+
import textwrap
11+
12+
from agent6.ui.cli import _common, _sandbox_paths
13+
14+
15+
def line(prefix: str, detail: str = "", *, hang: int = 4, warning: bool = False) -> None:
16+
"""Print a styled prefix and subdued detail, wrapping only the detail on a terminal."""
17+
if warning:
18+
prefix += _common.sgr("!", "33") + " "
19+
width = shutil.get_terminal_size().columns if sys.stdout.isatty() else 0
20+
size = len(re.sub(r"\x1b\[[0-9;]*m", "", prefix))
21+
if not width or size + len(detail) <= width:
22+
print(prefix + _common.sgr(detail, "2"))
23+
return
24+
first_word = detail.split(maxsplit=1)[0] if detail else ""
25+
if size + len(first_word) > width:
26+
print(prefix.rstrip())
27+
prefix, size = " " * hang, hang
28+
wrapped = textwrap.wrap(
29+
detail,
30+
width=max(width, hang + 1),
31+
initial_indent=" " * size,
32+
subsequent_indent=" " * hang,
33+
break_long_words=False,
34+
break_on_hyphens=False,
35+
)
36+
if wrapped:
37+
print(prefix + _common.sgr(wrapped[0][size:], "2"))
38+
for continuation in wrapped[1:]:
39+
print(_common.sgr(continuation, "2"))
40+
else:
41+
print(prefix.rstrip())
42+
43+
44+
def rows(entries: list[_sandbox_paths.Row]) -> None:
45+
"""Print a fixed-width purpose column without aligning annotations to the longest path."""
46+
for row in entries:
47+
prefix = f" {row.mode} {_common.sgr(f'{row.tag:4}', '2')} {row.path}"
48+
line(
49+
prefix + (" " if row.note else ""),
50+
f"({row.note})" if row.note else "",
51+
hang=14,
52+
warning=row.warning,
53+
)
54+
55+
56+
def result(status: str, name: str, detail: str) -> None:
57+
"""Print a check result with a readable status even without colour."""
58+
code = {"PASS": "32", "SKIP": "2", "FAIL": "31", "WARN": "33"}.get(status, "2")
59+
line(f"{_common.sgr(f'[{status}]', code)} {name}: ", detail)

0 commit comments

Comments
 (0)