From a1cf298fdfa1f7ecd7e91a20533dc150a0dc88df Mon Sep 17 00:00:00 2001 From: blockmandev <194144408+blockmandev@users.noreply.github.com> Date: Fri, 13 Nov 2026 09:04:10 -0600 Subject: [PATCH] insbx: the standalone sandbox is renamed from sbx `sbx` is also the name of Docker's sandbox CLI, which many agent projects use, and it is taken on crates.io, npm and PyPI. `insbx` is free on all three. Renamed everywhere, with no compatibility shims (nobody depends on the old name yet): - the binary: insbx / insbx.exe (CARGO_BIN_EXE_insbx in the tests) - environment: INSBX_BACKEND, INSBX_NATIVE, INSBX_WSL_DISTRO, INSBX_INNER_LAUNCH - incode's setting: sandbox_engine = "insbx" (src/sandbox/insbx.rs, tests/insbx_engine.rs) - Windows state: %LOCALAPPDATA%\insbx, %ProgramData%\insbx, the Global\insbx-grant-* and Global\insbx-acl mutexes, the insbx-offline account and its insbx_offline_* firewall filters - installers, release and CI workflows, package manifests, docs On a machine that ran the old `sbx setup-windows`, run `sbx setup-windows --remove` (old binary) and then `insbx setup-windows` as administrator: the account and its filters have new names. --- .github/workflows/ci.yml | 16 +-- .github/workflows/install-check.yml | 16 +-- .github/workflows/package-check.yml | 6 +- .github/workflows/release.yml | 8 +- Cargo.toml | 8 +- README.md | 32 +++--- TESTING.md | 18 ++-- crates/sandbox/Cargo.toml | 4 +- crates/sandbox/README.md | 132 +++++++++++------------ crates/sandbox/src/backend.rs | 36 +++---- crates/sandbox/src/helper.rs | 12 +-- crates/sandbox/src/lib.rs | 18 ++-- crates/sandbox/src/main.rs | 98 ++++++++--------- crates/sandbox/src/policy.rs | 2 +- crates/sandbox/src/proxy.rs | 8 +- crates/sandbox/src/seccomp.rs | 2 +- crates/sandbox/src/server.rs | 26 ++--- crates/sandbox/src/status.rs | 2 +- crates/sandbox/src/windows/acl.rs | 26 ++--- crates/sandbox/src/windows/helper.rs | 12 +-- crates/sandbox/src/windows/mod.rs | 43 ++++---- crates/sandbox/src/windows/offline.rs | 68 ++++++------ crates/sandbox/src/windows/setup.rs | 16 +-- crates/sandbox/src/wslpath.rs | 6 +- crates/sandbox/tests/escape.rs | 54 +++++----- crates/sandbox/tests/escape_macos.rs | 46 ++++---- crates/sandbox/tests/escape_windows.rs | 130 +++++++++++----------- crates/sandbox/tests/mcp.rs | 12 +-- crates/sandbox/tests/protect.rs | 8 +- crates/sandbox/tests/wsl.rs | 16 +-- scripts/install-windows.ps1 | 76 ++++++------- scripts/install.ps1 | 24 ++--- scripts/install.sh | 16 +-- scripts/package_manifests.py | 8 +- scripts/test-all.sh | 16 +-- scripts/test-windows.ps1 | 26 ++--- scripts/tests/test_package_manifests.py | 6 +- src/admin.rs | 12 +-- src/admin/tests.rs | 6 +- src/agent/claude_code/tests.rs | 4 +- src/main.rs | 2 +- src/sandbox/{sbx.rs => insbx.rs} | 76 ++++++------- src/sandbox/mod.rs | 40 +++---- src/self_update.rs | 20 ++-- src/tool_bridge.rs | 2 +- src/tools/bash.rs | 2 +- src/tools/bash_jobs.rs | 4 +- src/tools/shell_choice.rs | 2 +- tests/{sbx_engine.rs => insbx_engine.rs} | 18 ++-- 49 files changed, 622 insertions(+), 619 deletions(-) rename src/sandbox/{sbx.rs => insbx.rs} (86%) rename tests/{sbx_engine.rs => insbx_engine.rs} (87%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e14e5ee..4fa4845 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -179,23 +179,23 @@ jobs: - run: cargo test --bins env: INCODE_TEST_SHELLS: ${{ runner.os == 'Linux' && 'bash,fish,zsh,powershell' || runner.os == 'macOS' && 'bash,zsh,powershell' || 'bash,powershell' }} - # incode's commands under `sandbox_engine = "sbx"`, for real (Linux; + # incode's commands under `sandbox_engine = "insbx"`, for real (Linux; # it says it skipped elsewhere). - - run: cargo test --test sbx_engine - # The standalone sandbox (`sbx`). Its escape tests run on Linux and + - run: cargo test --test insbx_engine + # The standalone sandbox (`insbx`). Its escape tests run on Linux and # macOS, and skip, saying so, where the OS cannot enforce what they check. - run: cargo clippy -p incord-sandbox --all-targets -- -D warnings # Network deny natively on Windows (layer 2): the offline account and # its firewall filters. The runner is an administrator. Without this # the Windows network tests skip, saying so. - - name: sbx setup-windows + - name: insbx setup-windows if: runner.os == 'Windows' - run: cargo run -p incord-sandbox --bin sbx -- setup-windows - - name: sbx doctor (after setup-windows) + run: cargo run -p incord-sandbox --bin insbx -- setup-windows + - name: insbx doctor (after setup-windows) if: runner.os == 'Windows' env: - SBX_BACKEND: native - run: cargo run -p incord-sandbox --bin sbx -- doctor + INSBX_BACKEND: native + run: cargo run -p incord-sandbox --bin insbx -- doctor - run: cargo test -p incord-sandbox # A test that writes outside its temp dir lands in the checkout — a # Windows drive path is RELATIVE on Linux and macOS — and passes anyway. diff --git a/.github/workflows/install-check.yml b/.github/workflows/install-check.yml index 7b90d11..a8de36d 100644 --- a/.github/workflows/install-check.yml +++ b/.github/workflows/install-check.yml @@ -91,10 +91,10 @@ jobs: if: runner.os == 'Windows' shell: pwsh run: | - $sbx = Join-Path $env:RUNNER_TEMP 'incode-bin\sbx.exe' - & $sbx check --net deny + $insbx = Join-Path $env:RUNNER_TEMP 'incode-bin\insbx.exe' + & $insbx check --net deny if ($LASTEXITCODE -ne 0) { - Write-Output "::error::after install.ps1, sbx check --net deny exited ${LASTEXITCODE}: the sandbox setup did not run" + Write-Output "::error::after install.ps1, insbx check --net deny exited ${LASTEXITCODE}: the sandbox setup did not run" exit 1 } # Linux and macOS need no sandbox setup; install.sh checks what the @@ -105,10 +105,10 @@ jobs: shell: bash run: | set -uo pipefail - sbx="$RUNNER_TEMP/incode-bin/sbx" - "$sbx" check --fs workspace-write --net deny - echo "sbx check exited $?" - "$sbx" doctor + insbx="$RUNNER_TEMP/incode-bin/insbx" + "$insbx" check --fs workspace-write --net deny + echo "insbx check exited $?" + "$insbx" doctor if ! grep -Eq 'incode-install: sandbox( ready|: incode works)' "$RUNNER_TEMP/install.log"; then echo "::error::install.sh did not report the sandbox's state" exit 1 @@ -132,7 +132,7 @@ jobs: set -euo pipefail bin="$RUNNER_TEMP/incode-bin" want="${TAG#v}" - for program in incode sbx; do + for program in incode insbx; do got="$("$bin/$program" --version)" echo "$program --version: $got" if [ "$got" != "$program $want" ]; then diff --git a/.github/workflows/package-check.yml b/.github/workflows/package-check.yml index b216e9e..7d4bec7 100644 --- a/.github/workflows/package-check.yml +++ b/.github/workflows/package-check.yml @@ -95,7 +95,7 @@ jobs: # user PATH, which this already-running shell has not read. $links = Join-Path $env:LOCALAPPDATA 'Microsoft\WinGet\Links' $want = $env:TAG.TrimStart('v') - foreach ($program in 'incode', 'sbx') { + foreach ($program in 'incode', 'insbx') { $got = & (Join-Path $links "$program.exe") --version Write-Output "$program --version: $got" if ($got -ne "$program $want") { @@ -132,7 +132,7 @@ jobs: shell: pwsh run: | $want = $env:TAG.TrimStart('v') - foreach ($program in 'incode', 'sbx') { + foreach ($program in 'incode', 'insbx') { $got = & $program --version Write-Output "$program --version: $got" if ($got -ne "$program $want") { @@ -171,7 +171,7 @@ jobs: run: | set -euo pipefail want="${TAG#v}" - for program in incode sbx; do + for program in incode insbx; do got="$("$(brew --prefix)/bin/$program" --version)" echo "$program --version: $got" if [ "$got" != "$program $want" ]; then diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 816cad6..bb9f509 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,6 +1,6 @@ # Release binaries for a version tag. # -# Pushing `v1.2.3` builds `incode` and `sbx` for every platform below, packs +# Pushing `v1.2.3` builds `incode` and `insbx` for every platform below, packs # each pair as `incode-.tar.gz` (`.zip` on Windows), and publishes them # on a GitHub Release with a `SHA256SUMS` beside them. `scripts/install.sh`, # `scripts/install.ps1` and `incode update` all read exactly these names, so a @@ -99,17 +99,17 @@ jobs: set -euo pipefail stage="$(mktemp -d)" bin="target/${{ matrix.target }}/release" - cp "$bin/incode" "$bin/sbx" LICENSE NOTICE README.md "$stage/" + cp "$bin/incode" "$bin/insbx" LICENSE NOTICE README.md "$stage/" mkdir -p dist tar -C "$stage" -czf "dist/incode-${{ matrix.target }}.tar.gz" \ - incode sbx LICENSE NOTICE README.md + incode insbx LICENSE NOTICE README.md - name: Package (windows) if: runner.os == 'Windows' shell: pwsh run: | $stage = New-Item -ItemType Directory -Path (Join-Path $env:RUNNER_TEMP "stage") $bin = "target/${{ matrix.target }}/release" - Copy-Item "$bin/incode.exe", "$bin/sbx.exe", LICENSE, NOTICE, README.md $stage + Copy-Item "$bin/incode.exe", "$bin/insbx.exe", LICENSE, NOTICE, README.md $stage New-Item -ItemType Directory -Force -Path dist | Out-Null Compress-Archive -Path (Join-Path $stage "*") -DestinationPath "dist/incode-${{ matrix.target }}.zip" - uses: actions/upload-artifact@v4 diff --git a/Cargo.toml b/Cargo.toml index 798d348..1856965 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,10 +45,10 @@ rust-version = "1.88" name = "incode" path = "src/main.rs" -# Runs the sbx engine for real: its binary is sbx's helper, so it has its own +# Runs the insbx engine for real: its binary is insbx's helper, so it has its own # `main` (see the file). [[test]] -name = "sbx_engine" +name = "insbx_engine" harness = false [dependencies] @@ -85,8 +85,8 @@ base64 = "0.22" # NOTE: it turns on serde_json's `preserve_order` for the whole crate (feature # unification), so a `serde_json::Map` keeps insertion order instead of sorting. agent-client-protocol-schema = { version = "=1.9.1", default-features = false } -# The standalone sandbox in this workspace (`crates/sandbox`), as the `sbx` -# engine for shell commands: `sandbox_engine: "sbx"`. A path dependency, so +# The standalone sandbox in this workspace (`crates/sandbox`), as the `insbx` +# engine for shell commands: `sandbox_engine: "insbx"`. A path dependency, so # no new package; it adds the seccomp filter, the host-allowlist proxy and the # `.git` protection the built-in engine lacks. incord-sandbox = { path = "crates/sandbox" } diff --git a/README.md b/README.md index 82dd873..1239e2b 100644 --- a/README.md +++ b/README.md @@ -162,7 +162,7 @@ The design is in `docs/ARCHITECTURE.md`; the tool layer is its §5a and §5b. ## Install -Prebuilt `incode` (and `sbx`, the [standalone sandbox](crates/sandbox)) for +Prebuilt `incode` (and `insbx`, the [standalone sandbox](crates/sandbox)) for Linux (x86_64, aarch64; glibc), macOS (Intel, Apple silicon) and Windows (x86_64) are published on each GitHub release. The install scripts fetch the latest one, check it against the release's `SHA256SUMS`, and install it: @@ -180,7 +180,7 @@ irm https://raw.githubusercontent.com/incordai/incode/main/scripts/install.ps1 | At the end, both scripts set up the [sandbox](#the-os-sandbox) and install incode's [tools](#external-tools): -- **Windows**: `sbx setup-windows` (an offline account and firewall filters, so +- **Windows**: `insbx setup-windows` (an offline account and firewall filters, so commands can be cut off the network) runs through the Windows administrator prompt, once; it is skipped when already done. - **Linux and macOS**: nothing to set up and no root needed (Landlock and @@ -195,7 +195,7 @@ is missing. `INCODE_NO_SANDBOX_SETUP=1` skips the sandbox step and Set `INCODE_VERSION=v0.2.0` to pin a release instead of the latest. Once installed, `incode update --check` says whether a newer release exists, and -`incode update` installs it in place (sha256-checked; `sbx` is updated too when +`incode update` installs it in place (sha256-checked; `insbx` is updated too when it sits beside `incode`). The Linux binary links no desktop library: screen capture reads the X server over its socket, so it runs on a server with no X11, Wayland or GPU libraries installed. @@ -218,15 +218,15 @@ install -m755 target/release/incode ~/.local/bin/incode Copy-Item target\release\incode.exe $env:USERPROFILE\.local\bin\ ``` -**On Windows, also set up the sandbox** (`sbx`, which runs inside WSL2): +**On Windows, also set up the sandbox** (`insbx`, which runs inside WSL2): ```powershell powershell -ExecutionPolicy Bypass -File scripts\install-windows.ps1 ``` It installs WSL2 if it's missing (asks first; needs administrator rights -once and usually a restart, then run it again). It then builds `sbx` inside -WSL2 and puts `sbx.exe` on your PATH. `sbx.exe` forwards every command into +once and usually a restart, then run it again). It then builds `insbx` inside +WSL2 and puts `insbx.exe` on your PATH. `insbx.exe` forwards every command into WSL2, where the Linux sandbox confines it. macOS and Linux need no extra step. @@ -1192,12 +1192,12 @@ sandboxed. Where a mode cannot be applied, the command runs unconfined and the trace says which. **The engine**: `admin.json` `sandbox_engine` or `INCODE_SANDBOX_ENGINE`, -`builtin` (the default: everything above) or `sbx`, which confines the same -commands with [`sbx`](#sbx-the-same-sandbox-for-any-agent) instead, with the +`builtin` (the default: everything above) or `insbx`, which confines the same +commands with [`insbx`](#insbx-the-same-sandbox-for-any-agent) instead, with the same mode and network switch, and adds: - `sandbox_allow_hosts` (or `INCODE_SANDBOX_ALLOW_HOSTS`, comma-separated): the - only hosts a command may reach, through a proxy sbx runs for it; + only hosts a command may reach, through a proxy insbx runs for it; - `sandbox_loopback_ports` (`admin.json` only): this machine's own ports a command may also reach on `localhost`, `127.0.0.1` or `::1`, such as a dev server a browser test loads. Nothing else private opens. Like @@ -1209,19 +1209,19 @@ same mode and network switch, and adds: library stripped; a private temp directory per command. ```json -{ "sandbox_engine": "sbx", "sandbox_allow_hosts": ["crates.io", "static.crates.io", "github.com"] } +{ "sandbox_engine": "insbx", "sandbox_allow_hosts": ["crates.io", "static.crates.io", "github.com"] } ``` -Linux and macOS run it inside incode. Windows runs `sbx.exe` (installed beside +Linux and macOS run it inside incode. Windows runs `insbx.exe` (installed beside `incode.exe`), natively or inside WSL2 as `sandbox_backend` (or `INCODE_SANDBOX_BACKEND`) says: `native`, `wsl` or `auto`; under `wsl` the command runs in WSL's `sh`. What a machine cannot enforce is named in the -trace and `/doctor`; a run sbx cannot start at all is refused, not run +trace and `/doctor`; a run insbx cannot start at all is refused, not run unconfined. -### `sbx`: the same sandbox for any agent +### `insbx`: the same sandbox for any agent -`crates/sandbox` builds `sbx`, a standalone sandbox that doesn't depend on +`crates/sandbox` builds `insbx`, a standalone sandbox that doesn't depend on incode. It runs any command, whether an agent CLI, a test suite or Insi's workers, under one policy file: - writable roots, plus paths hidden even from reading (`deny_read`); @@ -1233,7 +1233,7 @@ It refuses a policy the machine cannot enforce in full instead of running with less. To confine a whole incode run: ```sh -sbx run -w . -w ~/.claude -w ~/.claude.json -w ~/.incode --wall 1800 -- incode -t "…" +insbx run -w . -w ~/.claude -w ~/.claude.json -w ~/.incode --wall 1800 -- incode -t "…" ``` Details, the policy format and what each OS enforces are in @@ -1436,7 +1436,7 @@ and `--admin` prints which layer decided each value. | `browser_bin` · `pdf_renderer` | For development, a headless browser executable that wins over the installed one · which program `RenderPdf` uses | | `sandbox` | `off` · `workspace-write` · `read-only`; unset follows the permission mode | | `sandbox_network` | `allow` (default) · `deny` — see [the OS sandbox](#the-os-sandbox) | -| `sandbox_engine` · `sandbox_allow_hosts` · `sandbox_loopback_ports` · `sandbox_backend` | `builtin` (default) · `sbx`; under sbx, the hosts a command may reach, this machine's own ports it may reach, and, on Windows, `native` · `wsl` · `auto` — see [the OS sandbox](#the-os-sandbox) | +| `sandbox_engine` · `sandbox_allow_hosts` · `sandbox_loopback_ports` · `sandbox_backend` | `builtin` (default) · `insbx`; under insbx, the hosts a command may reach, this machine's own ports it may reach, and, on Windows, `native` · `wsl` · `auto` — see [the OS sandbox](#the-os-sandbox) | | `codex_tools` | `incode` (default) · `own` — whose tools a `codex` model runs; see [the codex route](#the-codex-route-whose-tools) | | `agy_tools` | `incode` (default) · `own` — whose tools an `agy` model runs; see [the agy route](#the-agy-route-whose-tools) | | `hooks` (also `desktop_hooks`) | Your `pre_tool_use` / `post_tool_use` commands, run for every tool, and `user_prompt_submit`, run for each line you send. The event is JSON on stdin (`hook_event_name`, `session_id`, `cwd`, and `tool_name`/`tool_input` or `prompt`); exit 2 on a pre-tool command denies the call, on a prompt command refuses the line (the reason is shown and nothing is sent — not to the agent, not to the memory engine); a prompt command's stdout is added to that turn's context, and your line is never changed; bounded at 10 s. The prompt hook runs for lines typed in the REPL or sent over `--acp`, and for `-t`; for `/review` it sees the review prompt (the change included), and for `/run` each task's instruction before a worker or lane gets it — a refused task fails that attempt, and the hook's output rides that task's turn. It is taken from here and from your own plugins (`~/.incode/plugins/`), never from a project's `.incode/plugins/`, which arrives with whatever was cloned. `pre_compact` runs before `/compact` (event field `trigger`: `manual`, plus `custom_instructions`; when the agent compacts its own conversation, as a CLI agent does, it still runs and nothing is compacted by incode) and before the API route compacts on its own near the context window (`trigger`: `auto`, its output shown as incode's note during the turn); a CLI agent's own automatic compaction happens inside that agent and fires nothing, and `stop` when one of your turns has ended (`last_assistant_message`); neither can refuse anything, and their stdout is shown — with the compaction result, and with the turn's notices. `session_start` runs when a session opens (`source`: `startup`) and `session_end` when it closes (`reason`, e.g. `prompt_input_exit`, `other`), in the REPL, `--acp` and `-t`; neither can stop or keep anything, and their stdout is shown (on stderr for `-t`; a `--acp` session's end output goes to the trace, as the client has gone). They supersede a project's `.incode/lifecycle.json` (or the `lifecycle` section of `.incode.json`), whose `on_session_start`/`on_session_end` still run in the REPL — but only once you approve them as they are, since they arrive with whatever was cloned: `incode lifecycle show` lists them, `incode lifecycle approve` approves them, and any change needs approving again. `subagent_stop` runs when a sub-agent (the `Agent` tool) has finished, told `agent_type` (its definition, role, or `sub-agent`), `task`, `last_assistant_message` and `outcome` (`completed`, `failed` or `cancelled`); it cannot keep it working, and its output is traced, not shown. `notification` runs whenever incode would notify you (`notification_type`: `turn_done` or `input_needed`, plus `message`), in the background beside `notify_command`, in the REPL; its output is not shown | diff --git a/TESTING.md b/TESTING.md index 502af02..aa9f0e9 100644 --- a/TESTING.md +++ b/TESTING.md @@ -6,7 +6,7 @@ Everything CI runs, and the parts it cannot, from your own machine. ```sh scripts/test-all.sh # every part this machine has the toolchain for -scripts/test-all.sh rust sbx # only some parts: rust sbx python ts vscode +scripts/test-all.sh rust insbx # only some parts: rust insbx python ts vscode QUICK=1 scripts/test-all.sh # the same without clippy (the slowest step) ``` @@ -36,8 +36,8 @@ an email (`git config --global user.name ...`, `user.email ...`). | Part | Commands | What it covers | |---|---|---| | rust | `cargo fmt --all -- --check` · `cargo clippy --all-targets -- -D warnings` · `cargo test --lib` · `cargo test --bins` | incode itself: about 2,100 library and 50 binary tests | -| rust | `cargo test --test sbx_engine` | Real shell commands run under `sandbox_engine = "sbx"`: a write outside the workspace refused (with an unconfined control), a planted git hook undone, `GIT_DIR` stripped. Linux; says it skipped elsewhere | -| sbx | `cargo clippy -p incord-sandbox --all-targets -- -D warnings` · `cargo test -p incord-sandbox` | The standalone sandbox: escape tests per OS, the MCP server, `.git` protection, WSL path translation. On Windows CI, `sbx setup-windows` runs first so the native network-deny tests run | +| rust | `cargo test --test insbx_engine` | Real shell commands run under `sandbox_engine = "insbx"`: a write outside the workspace refused (with an unconfined control), a planted git hook undone, `GIT_DIR` stripped. Linux; says it skipped elsewhere | +| insbx | `cargo clippy -p incord-sandbox --all-targets -- -D warnings` · `cargo test -p incord-sandbox` | The standalone sandbox: escape tests per OS, the MCP server, `.git` protection, WSL path translation. On Windows CI, `insbx setup-windows` runs first so the native network-deny tests run | | python | `python3 -m unittest discover sdk/python/tests` | The Python SDK, against a fake incode | | ts | `cd sdk/typescript && npm install && npm test` | The TypeScript SDK, against the same fake | | vscode | `cd editors/vscode && npm install && npm run compile && npm test` | The VS Code extension's ACP client, against a fake agent | @@ -54,16 +54,16 @@ From the incode folder, in PowerShell: powershell -ExecutionPolicy Bypass -File scripts\test-windows.ps1 ``` -It builds `sbx`, runs its Windows tests (writes outside the workspace, child -processes, the time, CPU and memory limits, killing `sbx`, the environment, -exit codes, the MCP server) and writes `sbx-windows-report.txt`. These need +It builds `insbx`, runs its Windows tests (writes outside the workspace, child +processes, the time, CPU and memory limits, killing `insbx`, the environment, +exit codes, the MCP server) and writes `insbx-windows-report.txt`. These need real Windows: Wine cannot check Windows' own security. Nothing is installed and nothing outside a temp folder is changed. The network tests (deny and proxy natively: TCP, UDP, the offline account's grants, concurrent runs, the proxy's allowlist) run only where -`sbx setup-windows` has been run, from an elevated prompt (it makes a local -account and firewall filters; `sbx setup-windows --remove` undoes it); +`insbx setup-windows` has been run, from an elevated prompt (it makes a local +account and firewall filters; `insbx setup-windows --remove` undoes it); elsewhere they print SKIPPED. CI runs the setup on `windows-latest` before `cargo test -p incord-sandbox`, so they always run there. @@ -92,7 +92,7 @@ Things the suites cannot judge, worth a minute in a real terminal and editor: `.incode/commands/`, `/review`. - `incode review` on a branch with a change; `incode mcp login ` against a remote MCP server that needs a login; `incode plugin add` / `update`. -- `sandbox_engine = "sbx"` with `sandbox_allow_hosts`, then a command that +- `sandbox_engine = "insbx"` with `sandbox_allow_hosts`, then a command that reaches an allowed host and one that does not. - The VS Code extension (install the `.vsix` its README builds) and any ACP editor (`incode --acp`). diff --git a/crates/sandbox/Cargo.toml b/crates/sandbox/Cargo.toml index 4b6b2d8..c880fc5 100644 --- a/crates/sandbox/Cargo.toml +++ b/crates/sandbox/Cargo.toml @@ -15,7 +15,7 @@ name = "incord_sandbox" path = "src/lib.rs" [[bin]] -name = "sbx" +name = "insbx" path = "src/main.rs" [dependencies] @@ -28,7 +28,7 @@ libc = "0.2" # The native Windows sandbox (`src/windows`): a write-restricted token, an # ACE per writable root, and a job object; and for network deny (layer 2, -# `sbx setup-windows`) a local account, DPAPI for its password and Windows +# `insbx setup-windows`) a local account, DPAPI for its password and Windows # Filtering Platform filters. The same windows-sys incode itself already # resolves (0.61.2 is in Cargo.lock), so nothing new is downloaded; the extra # features only add bindings. diff --git a/crates/sandbox/README.md b/crates/sandbox/README.md index 7e83005..bc809d3 100644 --- a/crates/sandbox/README.md +++ b/crates/sandbox/README.md @@ -1,27 +1,27 @@ -# sbx: one sandbox for any agent +# insbx: one sandbox for any agent -`sbx` runs a command under one policy: what it may write, what it may read, +`insbx` runs a command under one policy: what it may write, what it may read, which hosts it may reach, which environment it starts with, and how much it may use. It works with any agent CLI (`claude`, `codex`, `incode`, `aider`, …), with a test suite a harness runs, or with a single tool call. The policy means the same thing on every platform. Where a platform cannot enforce part -of it, `sbx` says so before anything runs. By default it then refuses +of it, `insbx` says so before anything runs. By default it then refuses instead of running with less. ```sh # Write only in this project; network only to the package registry; 30 minutes. -sbx run -w . --allow-host crates.io --allow-host '*.crates.io' --wall 1800 -- cargo build +insbx run -w . --allow-host crates.io --allow-host '*.crates.io' --wall 1800 -- cargo build # An agent CLI confined to its workspace, with a folder it must not see. -sbx run -w . -w ~/.claude -w ~/.claude.json --deny-read ../private-checks -- claude -p "fix the failing test" +insbx run -w . -w ~/.claude -w ~/.claude.json --deny-read ../private-checks -- claude -p "fix the failing test" # What would this machine enforce? -sbx doctor -sbx check --policy agent.toml --json +insbx doctor +insbx check --policy agent.toml --json ``` It's a crate in the incode repository for now and doesn't depend on incode. -It builds to one binary, `sbx`, and a library, `incord_sandbox`. +It builds to one binary, `insbx`, and a library, `incord_sandbox`. ## The policy file @@ -53,7 +53,7 @@ file_size_mb = 1024 open_files = 4096 ``` -Every flag of `sbx run` has a policy key. Flags apply on top of `--policy`. +Every flag of `insbx run` has a policy key. Flags apply on top of `--policy`. An unknown key is an error, so a misspelt `wirte` can't silently do nothing. ## What is enforced, and how @@ -62,16 +62,16 @@ An unknown key is an error, so a misspelt `wirte` can't silently do nothing. |---|---|---|---| | filesystem: write | Landlock (5.13+) | Seatbelt | write-restricted token + a per-run ACE on each root | | filesystem: `deny_read` | Landlock | Seatbelt | **not enforced** (WSL2 does it) | -| network: `deny` | Landlock TCP (6.7+) + seccomp for every other socket | Seatbelt | after `sbx setup-windows`: runs as an offline account WFP filters cut off; else **not enforced** (WSL2 does it) | -| network: `proxy` | Landlock: TCP only to the proxy's port; seccomp as for `deny` | Seatbelt: outbound only to the proxy | after `sbx setup-windows`: the offline account may reach only the proxy's loopback ports; else **not enforced** (WSL2 does it) | +| network: `deny` | Landlock TCP (6.7+) + seccomp for every other socket | Seatbelt | after `insbx setup-windows`: runs as an offline account WFP filters cut off; else **not enforced** (WSL2 does it) | +| network: `proxy` | Landlock: TCP only to the proxy's port; seccomp as for `deny` | Seatbelt: outbound only to the proxy | after `insbx setup-windows`: the offline account may reach only the proxy's loopback ports; else **not enforced** (WSL2 does it) | | `.git/hooks`, `.git/config` | snapshotted, put back after the run | Seatbelt refuses the write | snapshotted, put back after the run | | signals, abstract Unix sockets | Landlock scopes (6.12+): only within the sandbox | Seatbelt default | the token cannot open other processes for writing (measured by incode) | | Windows programs (inside WSL2) | interop interpreter and sockets hidden, `WSL_INTEROP` removed, vsock refused | n/a | n/a | | limits | `setrlimit` + wall clock; no core dumps | `setrlimit` + wall clock; no core dumps | job object: wall clock, CPU and committed memory per process; **no** `file_size_mb`, `open_files` | | environment | yes | yes | yes | -On Windows, `sbx.exe` runs natively when native enforces the whole policy, -and forwards it to the Linux `sbx` inside WSL2 when it doesn't (see +On Windows, `insbx.exe` runs natively when native enforces the whole policy, +and forwards it to the Linux `insbx` inside WSL2 when it doesn't (see [Windows](#windows-native-or-wsl2)). - **Every process it starts.** The confinement is applied in a helper @@ -120,9 +120,9 @@ and forwards it to the Linux `sbx` inside WSL2 when it doesn't (see those ports on this machine, say a dev server a browser test loads, without `allow_private`. The request must name `localhost`, `127.0.0.1` or `::1`, and only a loopback address is connected to. Nothing else - private opens, and other ports stay refused. `sbx mcp` never gives a + private opens, and other ports stay refused. `insbx mcp` never gives a sandbox these ports, even when its base policy names some. - - When `sbx` itself runs behind an HTTP proxy, allowed requests are chained + - When `insbx` itself runs behind an HTTP proxy, allowed requests are chained through it, and that proxy does the resolving. Requests for this machine's own ports go straight to loopback, never through it. - **`deny_read`.** Landlock only grants, so a hidden path is carved out by @@ -136,17 +136,17 @@ and forwards it to the Linux `sbx` inside WSL2 when it doesn't (see - **Why:** a hook, or a `core.fsmonitor`/`core.hooksPath` line, is code git runs the next time anyone uses the repository, outside any sandbox. - **How (Linux):** Landlock can't make part of a writable root read-only - without also blocking file creation in the root, so `sbx` snapshots each + without also blocking file creation in the root, so `insbx` snapshots each root's `.git/hooks` and `.git/config` before the run. Anything changed is put back afterwards and reported (`protected path changed by the - command, restored …`, and `protected_restored` from `sbx mcp`). + command, restored …`, and `protected_restored` from `insbx mcp`). - **How (macOS):** Seatbelt also refuses the writes. - **Worktrees:** a `.git` file (`gitdir:`) and its `commondir` are followed. - **Opting out:** `--no-protect-git` for a run that should change hooks. - **Signals and abstract sockets.** On Landlock ABI v6 (Linux 6.12+) a sandboxed command can't signal processes outside its sandbox, or connect to - an abstract Unix socket made outside it (a D-Bus session bus, X11). `sbx + an abstract Unix socket made outside it (a D-Bus session bus, X11). `insbx doctor` says whether the kernel does this. - **Code the loader would inject.** `LD_PRELOAD`, `LD_AUDIT`, `DYLD_INSERT_LIBRARIES` and `DYLD_FORCE_FLAT_NAMESPACE` are removed by @@ -155,9 +155,9 @@ and forwards it to the Linux `sbx` inside WSL2 when it doesn't (see (`RLIMIT_CORE=0`), so a crash can't write the process's memory to disk. - **Process lifetime.** - With a wall-clock limit, the command gets its own process group. The - limit kills all of it, and `SIGINT`/`SIGTERM`/`SIGHUP` sent to `sbx` are + limit kills all of it, and `SIGINT`/`SIGTERM`/`SIGHUP` sent to `insbx` are passed on. - - If `sbx` is killed with `SIGKILL`, a supervisor kills the group too. + - If `insbx` is killed with `SIGKILL`, a supervisor kills the group too. - Without a limit, the command stays in the caller's process group, so the caller's own group kill reaches it. @@ -178,22 +178,22 @@ and forwards it to the Linux `sbx` inside WSL2 when it doesn't (see ## Windows: native, or WSL2 -`sbx.exe` has two backends, picked per run by `SBX_BACKEND`: +`insbx.exe` has two backends, picked per run by `INSBX_BACKEND`: -| `SBX_BACKEND` | what runs | +| `INSBX_BACKEND` | what runs | |---|---| | `auto` (default) | natively when native enforces everything the policy asks for; otherwise in WSL2 when it is set up; otherwise refused, naming both ways forward | | `native` | always natively; what it can't enforce is refused (strict) or reported (`--best-effort`) | -| `wsl` | always the Linux `sbx` inside WSL2 | +| `wsl` | always the Linux `insbx` inside WSL2 | -`SBX_NATIVE=1`, the older switch, still means `native`. `sbx doctor` shows +`INSBX_NATIVE=1`, the older switch, still means `native`. `insbx doctor` shows what native enforces and whether WSL2 forwarding is available. So a policy that confines files, environment and time runs natively. One that asks for `network: deny`/`proxy` runs natively too once -[`sbx setup-windows`](#network-natively-sbx-setup-windows) has been run on +[`insbx setup-windows`](#network-natively-insbx-setup-windows) has been run on the machine, and goes to WSL2 otherwise. `deny_read` always goes to WSL2. -`sbx mcp` follows the same rule from its ceilings: with `--net allow` it +`insbx mcp` follows the same rule from its ceilings: with `--net allow` it runs natively, with `--net deny` (its default) or `proxy` natively after the setup and in WSL2 without it. @@ -216,26 +216,26 @@ Windows. This crate's port is checked by its tests (incode measured about 2.5 s each way on 18,673 files). No file's contents or modification time change, and incode found the tree's ACLs byte-identical afterwards. A grant is written down first - (`%LOCALAPPDATA%\sbx\grants`). If `sbx` crashes, the next run removes + (`%LOCALAPPDATA%\insbx\grants`). If `insbx` crashes, the next run removes the ACE it left. A drive root and any folder holding your user profile are refused as roots. - **Everything it starts.** The command starts suspended, goes into a job object, and only then runs. Everything it starts is in the job too and cannot leave it. The job is killed when the command exits, at the - wall-clock limit, or when `sbx` itself dies. So on Windows nothing the + wall-clock limit, or when `insbx` itself dies. So on Windows nothing the command started outlives the run, even without a time limit. - **Limits.** `memory_mb` caps the memory each process *commits* (an allocation beyond it fails), which is not quite `RLIMIT_AS`. `cpu_secs` caps each process's user-mode CPU time. `file_size_mb` and `open_files` have no Windows equivalent: asking for them is reported not enforced. - (`sbx mcp` sets no file size limit on Windows for this reason.) + (`insbx mcp` sets no file size limit on Windows for this reason.) - **Programs.** The program is found on `PATH` with `PATHEXT`, never in the current folder, so a `cmd.exe` planted in the workspace is not picked up. A `.bat`/`.cmd` runs through `cmd.exe /d`, so `cmd` parses its arguments. - **Exit codes** are passed through whole (32 bits). **Not enforced natively, and why:** -- **Network, until `sbx setup-windows` has run.** No token restricts the +- **Network, until `insbx setup-windows` has run.** No token restricts the network (incode measured TCP, HTTP and HTTPS all working under it). Only an AppContainer does, and an AppContainer reads only what is granted to it: the workspace, your toolchains, your profile. So without the setup @@ -250,12 +250,12 @@ Windows. This crate's port is checked by its tests - **Git Bash and every msys program** fail to start under the token: the msys runtime maps a shared section the token may not map writable, and dies with `CreateFileMapping ..., Win32 error 5` (measured by incode). - Use `cmd` or PowerShell natively, or `SBX_BACKEND=wsl` for a POSIX shell. - `sbx mcp` scripts default to PowerShell on Windows. + Use `cmd` or PowerShell natively, or `INSBX_BACKEND=wsl` for a POSIX shell. + `insbx mcp` scripts default to PowerShell on Windows. - **Grants are visible.** While a run lasts, every object under a root carries the run's ACE, and the grant and revoke cost time on large trees. -### Network natively: `sbx setup-windows` +### Network natively: `insbx setup-windows` The Windows Filtering Platform can block a connection by the *user* who makes it. So, the way OpenAI Codex's Windows sandbox does it @@ -264,21 +264,21 @@ that the firewall cuts off, and `deny`/`proxy` runs start the command as that account. From an elevated prompt (Run as administrator), once: ```powershell -sbx setup-windows # or: ... --read C:\Users\me\.cargo --read C:\Users\me\.rustup -sbx doctor # [ok ] offline user ... -sbx run -w . --net deny -- cargo test # natively now, not in WSL2 -sbx setup-windows --remove # undoes all of it +insbx setup-windows # or: ... --read C:\Users\me\.cargo --read C:\Users\me\.rustup +insbx doctor # [ok ] offline user ... +insbx run -w . --net deny -- cargo test # natively now, not in WSL2 +insbx setup-windows --remove # undoes all of it ``` What it does (each step is idempotent; running it again resets the password and re-adds each filter): -1. **An account, `sbx-offline`**, member of `Users` only (it needs `Users` +1. **An account, `insbx-offline`**, member of `Users` only (it needs `Users` to log on locally and to read `C:\Windows` and `Program Files`; it is taken out of `Administrators` if anyone put it there), with a random password (256 bits) that is never shown, hidden from the sign-in screen. 2. **Its password**, DPAPI-protected with machine scope, in - `%ProgramData%\sbx\offline.conf`. The folder's ACL allows SYSTEM, + `%ProgramData%\insbx\offline.conf`. The folder's ACL allows SYSTEM, Administrators and the user who ran the setup, and nobody else: not `Users`, so not the offline account, and not a sandboxed command. Machine scope rather than user scope because the setup may run elevated as a @@ -297,7 +297,7 @@ password and re-adds each filter): 4. `--read ` (repeatable, kept across re-runs) lets the account read a folder: a toolchain under your profile (see *Reads* below). -At run time (unelevated), `sbx` starts its helper a second time as the +At run time (unelevated), `insbx` starts its helper a second time as the account with `CreateProcessWithLogonW`, the one call an unprivileged process can start another user's process with (`CreateProcessAsUserW` with that user's token needs `SeAssignPrimaryTokenPrivilege`, and @@ -306,13 +306,13 @@ runner the same way). That helper builds the write-restricted token from its own token, as above, and starts the command; the job object holds both, so limits, the wall clock, killing the tree and exit codes work as before. No profile is loaded for the account (Codex's runner doesn't either): it would -create `C:\Users\sbx-offline`, a home every run would share. The command +create `C:\Users\insbx-offline`, a home every run would share. The command gets the run's computed environment. What changes for the command: - **Reads.** It reads what the account may read, not what you may: system folders, and what each run grants it (the writable roots, the folder it - starts in, the `sbx` program, its private temp directory), plus folders + starts in, the `insbx` program, its private temp directory), plus folders granted with `--read`. A toolchain installed under your profile (`.cargo`, `.rustup`, a per-user Python or Node) needs `--read` once. Narrower than without network deny, never wider. One more right: the @@ -331,7 +331,7 @@ What changes for the command: With `--fs off` the command is not write-restricted but is still the account: it can write the folder it starts in and its temp directory, and what the account itself may write. -- **`sbx` itself** must be readable by the account; it is granted per run +- **`insbx` itself** must be readable by the account; it is granted per run when you own the file (a build under your profile), and is already when installed under `Program Files`. @@ -356,13 +356,13 @@ What changes for the command: requests for `localhost` past any proxy; tools that honour `HTTPS_PROXY` (`curl`, `git`, `cargo`, `npm`, `pip`) work. - Only the user who ran the setup can use it (the record is readable by - that user alone). Another user's `sbx doctor` says so. + that user alone). Another user's `insbx doctor` says so. - The thread objects of the account's helper get the account logon's default DACL, which is not measured yet; its process object is locked down explicitly (`D:P(A;;GA;;;SY)(A;;0x101000;;;OW)`). **Tested:** `tests/escape_windows.rs` runs on the `windows-latest` CI -runner after `sbx setup-windows` (CI runs it; the runner is an +runner after `insbx setup-windows` (CI runs it; the runner is an administrator): TCP to a local server and to the internet refused under `deny` with the filesystem confined, read-only and off (and allowed without `deny`); UDP refused; writes confined, temp writable, exit codes and @@ -370,13 +370,13 @@ administrator): TCP to a local server and to the internet refused under run and gone after; two concurrent runs sharing a root (the second ending first leaves the first its grant, and cannot write the first's other root); the proxy letting through only its allowlist, a direct connection refused; -`sbx mcp` running a deny sandbox's PowerShell script as the account. +`insbx mcp` running a deny sandbox's PowerShell script as the account. Without the setup these tests print SKIPPED. ### WSL2 Inside WSL2 the sandbox is the Linux one: Landlock, seccomp, the git -protection and `sbx mcp` all apply unchanged. +protection and `insbx mcp` all apply unchanged. **Setup, once** (PowerShell, from the incode folder): @@ -387,18 +387,18 @@ powershell -ExecutionPolicy Bypass -File scripts\install-windows.ps1 It: 1. installs WSL2 and Ubuntu if they're missing (asks first, one administrator prompt, usually a restart, then run it again); -2. builds the Linux `sbx` inside WSL2 at `~/.local/bin/sbx`; -3. builds `sbx.exe` and adds it to your PATH; -4. runs `sbx doctor`. +2. builds the Linux `insbx` inside WSL2 at `~/.local/bin/insbx`; +3. builds `insbx.exe` and adds it to your PATH; +4. runs `insbx doctor`. -**How `sbx.exe` forwards.** -- The command (`run`, `check`, `mcp`; `doctor` too under `SBX_BACKEND=wsl`) - is passed to the Linux `sbx` with `wsl.exe`, from the same folder. +**How `insbx.exe` forwards.** +- The command (`run`, `check`, `mcp`; `doctor` too under `INSBX_BACKEND=wsl`) + is passed to the Linux `insbx` with `wsl.exe`, from the same folder. - Paths are translated: `C:\work\app` becomes `/mnt/c/work/app`, and `\\wsl$\Ubuntu\home\me` becomes `/home/me`. -- Output, input and the exit code pass straight through, so `sbx mcp` works +- Output, input and the exit code pass straight through, so `insbx mcp` works for agents on Windows too. -- **Choosing a distribution:** `SBX_WSL_DISTRO` picks one other than the +- **Choosing a distribution:** `INSBX_WSL_DISTRO` picks one other than the default. - **Windows environment variables don't reach WSL** unless listed in `WSLENV` (for example `WSLENV=ANTHROPIC_API_KEY`). @@ -407,7 +407,7 @@ It: WSL2 adds one way out that plain Linux doesn't have: starting a Windows program (`cmd.exe`, `powershell.exe`, any `.exe` under `/mnt/c`), which runs on Windows, outside the sandbox. When the filesystem is confined and -WSL is detected, `sbx` closes it (`fs.block_wsl_interop`, on by default): +WSL is detected, `insbx` closes it (`fs.block_wsl_interop`, on by default): - WSL's interop interpreter (`/init`, read from `/proc/sys/fs/binfmt_misc/WSLInterop`) is hidden like a `deny_read` path, so no `.exe` can start; @@ -419,7 +419,7 @@ Hiding `/init` means `ls /` is refused inside the sandbox; files beneath `/` still read normally. **Network inside WSL2:** `network: deny` needs Landlock's TCP rules (Linux -6.7+). On an older WSL kernel only UDP/DNS are blocked, `sbx doctor` says +6.7+). On an older WSL kernel only UDP/DNS are blocked, `insbx doctor` says the network is not enforced, and strict mode refuses `deny`/`proxy` rather than pretend. Update WSL (`wsl --update`) for a newer kernel. @@ -436,24 +436,24 @@ relying on this. |---|---| | the command's | it ran | | 124 | the wall-clock limit killed it | -| 125 | `sbx` refused (strict, or a bad policy) or failed | +| 125 | `insbx` refused (strict, or a bad policy) or failed | | 126 / 127 | the command could not be run / found | | 128 + n | it was killed by signal n | -## Sandboxes as a service: `sbx mcp` +## Sandboxes as a service: `insbx mcp` -`sbx mcp` is an MCP server (stdio) that lets an agent work in sandboxes: +`insbx mcp` is an MCP server (stdio) that lets an agent work in sandboxes: create one, write scripts and files into it, run them, read what they produced, and delete it. Any agent that speaks MCP can use it: Claude Code, Codex, incode, or your own. ```json -{ "mcpServers": { "sbx": { "command": "sbx", "args": ["mcp", "--net", "proxy", "--allow-host", "pypi.org", "--allow-host", "*.pythonhosted.org"] } } } +{ "mcpServers": { "insbx": { "command": "insbx", "args": ["mcp", "--net", "proxy", "--allow-host", "pypi.org", "--allow-host", "*.pythonhosted.org"] } } } ``` | Tool | What it does | |---|---| -| `sandbox_create` | A private folder. Network `deny` unless the agent asks for `proxy` with hosts (or `allow`) within the server's limits. Natively on Windows `deny` and `proxy` need `sbx setup-windows` first; without it asking for them is refused at once, saying so. | +| `sandbox_create` | A private folder. Network `deny` unless the agent asks for `proxy` with hosts (or `allow`) within the server's limits. Natively on Windows `deny` and `proxy` need `insbx setup-windows` first; without it asking for them is refused at once, saying so. | | `sandbox_write_file` | Write a script or file, creating folders; `executable` sets 755. | | `sandbox_run` | Run `command` (argv) or `script` (text, run with `interpreter`, default `sh`; PowerShell natively on Windows) with optional `stdin`, `cwd` and `timeout_secs`. Returns `exit_code`, `stdout`, `stderr` (64 KB each), `timed_out` and `network_refused`. | | `sandbox_read_file` / `sandbox_list` | Read results back (256 KB at most). | @@ -506,7 +506,7 @@ holds the proxy and the temp directory. ## Tests `cargo test -p incord-sandbox` runs: -- `tests/mcp.rs`: `sbx mcp` driven over stdio like an agent drives it. It writes a script, runs it and reads its result; tries escapes (writing outside, the network, host secrets, a planted symlink, `..`, absolute paths); checks the time limit and background cleanup, the limits on what an agent may ask for, and that sandboxes are removed on exit; +- `tests/mcp.rs`: `insbx mcp` driven over stdio like an agent drives it. It writes a script, runs it and reads its result; tries escapes (writing outside, the network, host secrets, a planted symlink, `..`, absolute paths); checks the time limit and background cleanup, the limits on what an agent may ask for, and that sandboxes are removed on exit; - the unit tests (policy, environment, allowlist, Seatbelt profile, and the Windows backend's pure parts on every platform: backend choice, SID and record handling, root checks, program lookup, command-line quoting, job @@ -522,12 +522,12 @@ holds the proxy and the temp directory. - on Windows (`tests/escape_windows.rs`, with only `cmd` and PowerShell): writes outside the root, the grant held during the run and gone after, read-only and its private temp, child `cmd` and PowerShell, a planted - program in the current folder, the wall limit and killing `sbx` taking + program in the current folder, the wall limit and killing `insbx` taking the whole tree, the job's memory and CPU limits, the environment, exit codes, refusing what native can't enforce, `auto` without WSL, `doctor`, - and `sbx mcp` run natively; and, where `sbx setup-windows` has run (CI + and `insbx mcp` run natively; and, where `insbx setup-windows` has run (CI runs it first), network deny and proxy natively (see - [above](#network-natively-sbx-setup-windows)). + [above](#network-natively-insbx-setup-windows)). Each escape test skips, and says so, on a kernel that cannot enforce what it checks. diff --git a/crates/sandbox/src/backend.rs b/crates/sandbox/src/backend.rs index 8050b70..516d4f9 100644 --- a/crates/sandbox/src/backend.rs +++ b/crates/sandbox/src/backend.rs @@ -4,18 +4,18 @@ //! environment and the limits a job object can carry, but not the network //! and not `deny_read` ([`crate::windows`]). WSL2 runs the Linux sandbox, //! which enforces all of it, at the price of a Linux userland: the command -//! must exist inside WSL, and paths are translated. So `sbx.exe` picks per -//! invocation, from `SBX_BACKEND`: +//! must exist inside WSL, and paths are translated. So `insbx.exe` picks per +//! invocation, from `INSBX_BACKEND`: //! //! - `native`: always natively. What native cannot enforce is refused //! (strict) or reported (`--best-effort`), as on every platform. -//! - `wsl`: always forwarded to the Linux `sbx` inside WSL2. +//! - `wsl`: always forwarded to the Linux `insbx` inside WSL2. //! - `auto` (the default): natively when native enforces everything the //! policy asks for; otherwise forwarded to WSL2 when it is set up; //! otherwise refused, with both ways forward named, unless `--best-effort` //! accepts running natively with less. //! -//! `SBX_NATIVE=1`, the older switch, still means `native`. +//! `INSBX_NATIVE=1`, the older switch, still means `native`. //! //! The choice is a pure function of the policy's gaps and whether WSL is //! ready, so it is tested on every platform. @@ -42,23 +42,23 @@ pub const WSL_SETUP: &str = "set up WSL2 forwarding once (PowerShell, from the i powershell -ExecutionPolicy Bypass -File scripts\\install-windows.ps1"; impl Backend { - /// The backend from the environment: `SBX_BACKEND`, else `SBX_NATIVE` + /// The backend from the environment: `INSBX_BACKEND`, else `INSBX_NATIVE` /// (any non-empty value but `0` means native), else `auto`. /// /// # Errors - /// When `SBX_BACKEND` names no backend: a typo must not silently pick one. + /// When `INSBX_BACKEND` names no backend: a typo must not silently pick one. pub fn from_env(var: impl Fn(&str) -> Option) -> Result { - if let Some(v) = var("SBX_BACKEND").filter(|v| !v.trim().is_empty()) { + if let Some(v) = var("INSBX_BACKEND").filter(|v| !v.trim().is_empty()) { return match v.trim().to_ascii_lowercase().as_str() { "native" => Ok(Self::Native), "wsl" => Ok(Self::Wsl), "auto" => Ok(Self::Auto), other => Err(format!( - "SBX_BACKEND=`{other}` is not a backend (native | wsl | auto)" + "INSBX_BACKEND=`{other}` is not a backend (native | wsl | auto)" )), }; } - match var("SBX_NATIVE") { + match var("INSBX_NATIVE") { Some(v) if !v.is_empty() && v != "0" => Ok(Self::Native), _ => Ok(Self::Auto), } @@ -95,7 +95,7 @@ pub fn choose( Err(why) => Choice::Refuse(format!( "this policy asks for what native Windows cannot enforce:\n {}\n\ and WSL2 forwarding, which would, is not available ({why}).\n\ - Either {WSL_SETUP} (sbx then forwards such policies there by itself), \ + Either {WSL_SETUP} (insbx then forwards such policies there by itself), \ or drop those parts of the policy (or accept them unenforced with \ --best-effort).", native_gaps.join("\n ") @@ -118,30 +118,30 @@ mod tests { } #[test] - fn the_backend_comes_from_sbx_backend_then_sbx_native() { + fn the_backend_comes_from_insbx_backend_then_insbx_native() { assert_eq!(Backend::from_env(env(&[])), Ok(Backend::Auto)); assert_eq!( - Backend::from_env(env(&[("SBX_BACKEND", "WSL")])), + Backend::from_env(env(&[("INSBX_BACKEND", "WSL")])), Ok(Backend::Wsl) ); assert_eq!( - Backend::from_env(env(&[("SBX_BACKEND", "native")])), + Backend::from_env(env(&[("INSBX_BACKEND", "native")])), Ok(Backend::Native) ); assert_eq!( - Backend::from_env(env(&[("SBX_NATIVE", "1")])), + Backend::from_env(env(&[("INSBX_NATIVE", "1")])), Ok(Backend::Native) ); assert_eq!( - Backend::from_env(env(&[("SBX_NATIVE", "0")])), + Backend::from_env(env(&[("INSBX_NATIVE", "0")])), Ok(Backend::Auto) ); - // SBX_BACKEND wins over the older switch. + // INSBX_BACKEND wins over the older switch. assert_eq!( - Backend::from_env(env(&[("SBX_BACKEND", "auto"), ("SBX_NATIVE", "1")])), + Backend::from_env(env(&[("INSBX_BACKEND", "auto"), ("INSBX_NATIVE", "1")])), Ok(Backend::Auto) ); - assert!(Backend::from_env(env(&[("SBX_BACKEND", "wls")])).is_err()); + assert!(Backend::from_env(env(&[("INSBX_BACKEND", "wls")])).is_err()); } #[test] diff --git a/crates/sandbox/src/helper.rs b/crates/sandbox/src/helper.rs index 7701a7e..65d8e9f 100644 --- a/crates/sandbox/src/helper.rs +++ b/crates/sandbox/src/helper.rs @@ -22,7 +22,7 @@ pub fn enter_if_requested() { let code = match enter(&rest) { Ok(never) => match never {}, Err(e) => { - eprintln!("sbx: {e}"); + eprintln!("insbx: {e}"); e.code } }; @@ -173,7 +173,7 @@ fn confine(spec: &EnterSpec) -> Result<(), EnterError> { if spec.strict { return Err(sandbox_err(e)); } - eprintln!("sbx: limit not applied (best effort): {e}"); + eprintln!("insbx: limit not applied (best effort): {e}"); } #[cfg(target_os = "linux")] { @@ -181,7 +181,7 @@ fn confine(spec: &EnterSpec) -> Result<(), EnterError> { if spec.strict { return Err(sandbox_err(format!("Landlock: {e}"))); } - eprintln!("sbx: Landlock not applied (best effort): {e}"); + eprintln!("insbx: Landlock not applied (best effort): {e}"); } let network = spec.net_mode != NetMode::Allow; let fs = spec.fs_mode != FsMode::Off && seccomp::available(); @@ -190,7 +190,7 @@ fn confine(spec: &EnterSpec) -> Result<(), EnterError> { if spec.strict && network { return Err(sandbox_err(format!("seccomp: {e}"))); } - eprintln!("sbx: seccomp not applied (best effort): {e}"); + eprintln!("insbx: seccomp not applied (best effort): {e}"); } } } @@ -244,7 +244,7 @@ fn supervise(program: &OsString, args: &[OsString], parent: libc::pid_t) -> Neve .unwrap_or(1) } Err(e) => { - eprintln!("sbx: cannot run {}: {e}", Path::new(program).display()); + eprintln!("insbx: cannot run {}: {e}", Path::new(program).display()); if e.kind() == std::io::ErrorKind::NotFound { 127 } else { @@ -348,7 +348,7 @@ mod tests { } } - /// A process not started as the helper (no `__sbx-enter` first) goes on + /// A process not started as the helper (no `__insbx-enter` first) goes on /// at once: this test binary was not, and the call returns. #[test] fn a_process_not_started_as_the_helper_carries_on() { diff --git a/crates/sandbox/src/lib.rs b/crates/sandbox/src/lib.rs index c45c983..67086f2 100644 --- a/crates/sandbox/src/lib.rs +++ b/crates/sandbox/src/lib.rs @@ -11,7 +11,7 @@ //! # How a command is confined //! //! ```text -//! parent (sbx, or your program) helper (same binary, re-executed) +//! parent (insbx, or your program) helper (same binary, re-executed) //! private temp dir setrlimit //! allowlisting proxy (network=proxy) Landlock restrict_self (Linux) //! environment computed seccomp socket filter (Linux, network) @@ -32,7 +32,7 @@ //! |---|---|---|---| //! | Linux | Landlock (5.13+) | Landlock TCP (6.7+) + seccomp | setrlimit + wall | //! | macOS | Seatbelt | Seatbelt | setrlimit + wall | -//! | Windows | write-restricted token + ACL grant (writes only; no `deny_read`) | after `sbx setup-windows`: an offline account WFP cuts off ([`windows::offline`]); else WSL2 (see [`backend`]) | job object + wall | +//! | Windows | write-restricted token + ACL grant (writes only; no `deny_read`) | after `insbx setup-windows`: an offline account WFP cuts off ([`windows::offline`]); else WSL2 (see [`backend`]) | job object + wall | pub mod backend; pub mod env; @@ -68,7 +68,7 @@ use serde::{Deserialize, Serialize}; pub use policy::{FsMode, Inherit, Limits, NetMode, Policy}; /// The first argument that turns the binary into the helper. -pub const ENTER_ARG: &str = "__sbx-enter"; +pub const ENTER_ARG: &str = "__insbx-enter"; /// Exit code for "the sandbox refused or failed", as `docker run` uses it. pub const EXIT_SANDBOX: i32 = 125; @@ -176,7 +176,7 @@ pub(crate) struct InnerLaunch { /// The variable [`InnerLaunch`] travels in; removed before the command /// starts. #[cfg_attr(not(windows), allow(dead_code))] -pub(crate) const INNER_ENV: &str = "SBX_INNER_LAUNCH"; +pub(crate) const INNER_ENV: &str = "INSBX_INNER_LAUNCH"; /// The helper's argument that says its spec is in [`INNER_ENV`]. #[cfg_attr(not(windows), allow(dead_code))] pub(crate) const INNER_ARG: &str = "@env"; @@ -351,7 +351,7 @@ impl Sandbox { None => std::env::current_exe().map_err(|e| format!("cannot name the helper: {e}"))?, }; // Windows, network deny or proxy: the command runs as the offline - // account, when `sbx setup-windows` has made it (otherwise the gap + // account, when `insbx setup-windows` has made it (otherwise the gap // was refused above, or accepted with --best-effort). #[cfg(windows)] let mut offline = if self.policy.network.mode == NetMode::Allow { @@ -493,7 +493,7 @@ impl Sandbox { Ok(lease) => Ok(Some(lease)), Err(e) if self.strict => Err(e), Err(e) => { - eprintln!("sbx: writes not confined and network not denied (best effort): {e}"); + eprintln!("insbx: writes not confined and network not denied (best effort): {e}"); *offline = None; Ok(None) } @@ -789,7 +789,7 @@ extern "C" fn forward(sig: libc::c_int) { } /// Pass SIGINT, SIGTERM, SIGHUP and SIGQUIT on to the command's process -/// group, so a caller that stops sbx stops what sbx started. +/// group, so a caller that stops insbx stops what insbx started. fn forward_signals_to_group(pid: u32) { #[cfg(unix)] { @@ -862,7 +862,7 @@ impl TempDir { .map(|d| d.subsec_nanos()) .unwrap_or(0); let name = format!( - "sbx-{}-{}-{nanos:x}", + "insbx-{}-{}-{nanos:x}", std::process::id(), NEXT.fetch_add(1, Ordering::Relaxed) ); @@ -917,7 +917,7 @@ mod tests { sid: None, parent_pid: Some(7), offline: Offline::Launch, - offline_record: Some(PathBuf::from(r"C:\ProgramData\sbx\offline.conf")), + offline_record: Some(PathBuf::from(r"C:\ProgramData\insbx\offline.conf")), } } diff --git a/crates/sandbox/src/main.rs b/crates/sandbox/src/main.rs index 9b656f2..a3393f2 100644 --- a/crates/sandbox/src/main.rs +++ b/crates/sandbox/src/main.rs @@ -1,10 +1,10 @@ -//! `sbx`: run a command under a sandbox policy. +//! `insbx`: run a command under a sandbox policy. //! //! ```text -//! sbx run [options] -- [args...] -//! sbx check [options] what this machine would enforce of the policy -//! sbx doctor what this machine can enforce at all -//! sbx mcp [options] sandboxes as an MCP server an agent drives +//! insbx run [options] -- [args...] +//! insbx check [options] what this machine would enforce of the policy +//! insbx doctor what this machine can enforce at all +//! insbx mcp [options] sandboxes as an MCP server an agent drives //! ``` use std::ffi::OsString; @@ -16,22 +16,22 @@ use incord_sandbox::{ }; const USAGE: &str = "\ -sbx - run any command under one sandbox policy +insbx - run any command under one sandbox policy USAGE: - sbx run [OPTIONS] -- [ARGS...] - sbx check [OPTIONS] print what this machine enforces of the policy (JSON with --json) - sbx doctor print what this machine can enforce at all - sbx mcp [MCP OPTIONS] serve sandboxes over MCP (stdio): an agent creates one, + insbx run [OPTIONS] -- [ARGS...] + insbx check [OPTIONS] print what this machine enforces of the policy (JSON with --json) + insbx doctor print what this machine can enforce at all + insbx mcp [MCP OPTIONS] serve sandboxes over MCP (stdio): an agent creates one, writes scripts into it, runs them, reads the results - sbx setup-windows [--read ]... [--proxy-ports ] | --remove + insbx setup-windows [--read ]... [--proxy-ports ] | --remove Windows, as administrator, once: network deny and proxy natively (an offline account the firewall cuts off). --read lets that account read a folder (a toolchain); --remove undoes all of it MCP OPTIONS (the ceilings; an agent can ask for less, never more): - --root where sandboxes live (default: /sbx-mcp-) + --root where sandboxes live (default: /insbx-mcp-) --net most network a sandbox may have: deny (default) | proxy | allow --allow-host with --net proxy: a host sandboxes may name (repeatable) --max-wall longest one run may take (default 600) @@ -69,7 +69,7 @@ POLICY (a file, then flags on top of it): -q, --quiet no report on stderr EXIT: - the command's own code; 124 when --wall killed it; 125 when sbx refused or failed; + the command's own code; 124 when --wall killed it; 125 when insbx refused or failed; 126/127 when the command could not be run / found. "; @@ -85,7 +85,7 @@ fn main() -> ExitCode { match real_main(args) { Ok(code) => exit_with(code), Err(e) => { - eprintln!("sbx: {e}"); + eprintln!("insbx: {e}"); ExitCode::from(EXIT_SANDBOX as u8) } } @@ -102,7 +102,7 @@ fn exit_with(code: i32) -> ExitCode { ExitCode::from(u8::try_from(code.clamp(0, 255)).unwrap_or(1)) } -/// `sbx.exe` on Windows: run natively, or forward to the Linux `sbx` inside +/// `insbx.exe` on Windows: run natively, or forward to the Linux `insbx` inside /// WSL2, where Landlock and seccomp do the confining. #[cfg(windows)] mod windows_backend { @@ -114,8 +114,8 @@ mod windows_backend { use incord_sandbox::enforcement; use incord_sandbox::wslpath::{to_wsl, translate_args}; - /// Where the installer puts the Linux `sbx` inside WSL. - const IN_WSL: &str = "$HOME/.local/bin/sbx"; + /// Where the installer puts the Linux `insbx` inside WSL. + const IN_WSL: &str = "$HOME/.local/bin/insbx"; /// `Some(exit)` when this invocation was forwarded (or refused); `None` /// to run it natively. @@ -123,7 +123,7 @@ mod windows_backend { let backend = match Backend::from_env(|k| std::env::var(k).ok()) { Ok(b) => b, Err(e) => { - eprintln!("sbx: {e}"); + eprintln!("insbx: {e}"); return Some(ExitCode::from(125)); } }; @@ -155,11 +155,11 @@ mod windows_backend { // `check` is a report: say what native enforces (exit 1 for the // gaps) and why WSL was not used. Choice::Refuse(why) if sub == "check" => { - eprintln!("sbx: {why}"); + eprintln!("insbx: {why}"); None } Choice::Refuse(why) => { - eprintln!("sbx: {why}"); + eprintln!("insbx: {why}"); Some(ExitCode::from(125)) } } @@ -170,7 +170,7 @@ mod windows_backend { PathBuf::from(root).join("System32").join("wsl.exe") } - /// Whether forwarding would work: `wsl.exe` exists and the Linux `sbx` + /// Whether forwarding would work: `wsl.exe` exists and the Linux `insbx` /// is installed in the distribution. Starts WSL, so asked only when it /// matters. pub fn wsl_ready() -> Result<(), String> { @@ -179,7 +179,7 @@ mod windows_backend { return Err("wsl.exe was not found: WSL is not installed".into()); } let mut cmd = Command::new(&exe); - if let Some(distro) = std::env::var_os("SBX_WSL_DISTRO") { + if let Some(distro) = std::env::var_os("INSBX_WSL_DISTRO") { cmd.arg("-d").arg(distro); } let status = cmd @@ -191,19 +191,19 @@ mod windows_backend { match status { Ok(s) if s.success() => Ok(()), Ok(_) => Err(format!( - "the Linux sbx is not installed inside WSL at {IN_WSL}, or WSL has no Linux \ + "the Linux insbx is not installed inside WSL at {IN_WSL}, or WSL has no Linux \ distribution" )), Err(e) => Err(format!("wsl.exe cannot start: {e}")), } } - /// The Windows lines of `sbx doctor`: the backend, and whether WSL2 + /// The Windows lines of `insbx doctor`: the backend, and whether WSL2 /// forwarding is there for what native cannot enforce. pub fn doctor() { match Backend::from_env(|k| std::env::var(k).ok()) { Ok(b) => println!( - " [info] backend SBX_BACKEND={}: {}", + " [info] backend INSBX_BACKEND={}: {}", b.as_str(), match b { Backend::Auto => "native when it enforces the whole policy, else WSL2", @@ -215,21 +215,21 @@ mod windows_backend { } match incord_sandbox::windows::offline_setup() { Ok(r) => println!( - " [ok ] offline user {} and its firewall filters are set up (sbx setup-windows): \ + " [ok ] offline user {} and its firewall filters are set up (insbx setup-windows): \ network deny and proxy run natively (proxy ports {}-{})", incord_sandbox::windows::offline::ACCOUNT, r.proxy_ports.0, r.proxy_ports.1 ), Err(why) => println!( - " [no ] offline user {why}; for network deny natively, run `sbx setup-windows` \ + " [no ] offline user {why}; for network deny natively, run `insbx setup-windows` \ as administrator" ), } match wsl_ready() { Ok(()) => println!( " [ok ] WSL2 forwarding available: network deny/proxy and deny_read \ - are enforced there (run `SBX_BACKEND=wsl sbx doctor` for its report)" + are enforced there (run `INSBX_BACKEND=wsl insbx doctor` for its report)" ), Err(why) => println!(" [no ] WSL2 {why}; to have it, {WSL_SETUP}"), } @@ -239,7 +239,7 @@ mod windows_backend { match run(args) { Ok(code) => super::exit_with(code), Err(e) => { - eprintln!("sbx: {e}"); + eprintln!("insbx: {e}"); ExitCode::from(125) } } @@ -263,7 +263,7 @@ mod windows_backend { ) })?; let mut cmd = Command::new(wsl_exe()); - if let Some(distro) = std::env::var_os("SBX_WSL_DISTRO") { + if let Some(distro) = std::env::var_os("INSBX_WSL_DISTRO") { cmd.arg("-d").arg(distro); } cmd.arg("--cd") @@ -272,10 +272,10 @@ mod windows_backend { .arg("sh") .arg("-c") .arg(format!( - "[ -x \"{IN_WSL}\" ] || {{ echo 'sbx is not installed inside WSL' >&2; exit 126; }}; \ + "[ -x \"{IN_WSL}\" ] || {{ echo 'insbx is not installed inside WSL' >&2; exit 126; }}; \ exec \"{IN_WSL}\" \"$@\"" )) - .arg("sbx") + .arg("insbx") .args(&args); let status = cmd .status() @@ -285,7 +285,7 @@ mod windows_backend { // command's own codes pass through. if code < 0 || code == 126 { eprintln!( - "sbx: forwarding to WSL2 failed; {WSL_SETUP}. Or set SBX_BACKEND=native to run \ + "insbx: forwarding to WSL2 failed; {WSL_SETUP}. Or set INSBX_BACKEND=native to run \ natively (writes, environment and limits confined; network and deny_read not)." ); } @@ -313,7 +313,7 @@ fn real_main(args: Vec) -> Result { Ok(0) } "-V" | "--version" => { - println!("sbx {}", env!("CARGO_PKG_VERSION")); + println!("insbx {}", env!("CARGO_PKG_VERSION")); Ok(0) } "doctor" => { @@ -336,7 +336,7 @@ fn real_main(args: Vec) -> Result { "run" => run(parse(&args[1..])?), "mcp" => mcp(&args[1..]), "setup-windows" => setup_windows(&args[1..]), - other => Err(format!("unknown command `{other}` (try `sbx --help`)")), + other => Err(format!("unknown command `{other}` (try `insbx --help`)")), } } @@ -349,25 +349,25 @@ fn run(o: Options) -> Result { let e = sandbox.enforcement(); if !o.quiet { for gap in e.gaps() { - eprintln!("sbx: {gap}"); + eprintln!("insbx: {gap}"); } } let outcome = sandbox.run(program, rest, &o.cwd)?; if !o.quiet { for d in outcome.decisions.iter().filter(|d| !d.allowed) { - eprintln!("sbx: network refused {} ({})", d.target, d.reason); + eprintln!("insbx: network refused {} ({})", d.target, d.reason); } for r in &outcome.restored { - eprintln!("sbx: protected path changed by the command, {r}"); + eprintln!("insbx: protected path changed by the command, {r}"); } if outcome.timed_out { - eprintln!("sbx: killed after the wall-clock limit"); + eprintln!("insbx: killed after the wall-clock limit"); } } Ok(outcome.code()) } -/// `sbx setup-windows`: see [`incord_sandbox::windows::offline`]. +/// `insbx setup-windows`: see [`incord_sandbox::windows::offline`]. fn setup_windows(args: &[OsString]) -> Result { let args: Vec = args .iter() @@ -381,13 +381,13 @@ fn setup_windows(args: &[OsString]) -> Result { #[cfg(windows)] { for line in incord_sandbox::windows::setup_windows(&parsed)? { - println!("sbx setup-windows: {line}"); + println!("insbx setup-windows: {line}"); } if parsed.remove { - println!("sbx setup-windows: removed; network deny now needs WSL2 again"); + println!("insbx setup-windows: removed; network deny now needs WSL2 again"); } else { println!( - "sbx setup-windows: done; `sbx run --net deny ...` now runs natively (see `sbx doctor`)" + "insbx setup-windows: done; `insbx run --net deny ...` now runs natively (see `insbx doctor`)" ); } Ok(0) @@ -406,7 +406,7 @@ fn setup_windows(args: &[OsString]) -> Result { fn mcp(args: &[OsString]) -> Result { let (root, mut ceilings) = parse_mcp(args)?; let root = root - .unwrap_or_else(|| std::env::temp_dir().join(format!("sbx-mcp-{}", std::process::id()))); + .unwrap_or_else(|| std::env::temp_dir().join(format!("insbx-mcp-{}", std::process::id()))); std::fs::create_dir_all(&root).map_err(|e| format!("{}: {e}", root.display()))?; ceilings.root = incord_sandbox::plain_path(std::fs::canonicalize(&root).map_err(|e| e.to_string())?); @@ -417,7 +417,7 @@ fn mcp(args: &[OsString]) -> Result { Ok(0) } -/// `sbx mcp`'s options: the sandboxes' root (if given) and the ceilings. +/// `insbx mcp`'s options: the sandboxes' root (if given) and the ceilings. fn parse_mcp( args: &[OsString], ) -> Result<(Option, incord_sandbox::server::Ceilings), String> { @@ -463,7 +463,7 @@ fn parse_mcp( } "--keep" => ceilings.keep = true, "--best-effort" => ceilings.best_effort = true, - other => return Err(format!("sbx mcp: unknown option `{other}`")), + other => return Err(format!("insbx mcp: unknown option `{other}`")), } i += 1; } @@ -533,7 +533,7 @@ fn parse(args: &[OsString]) -> Result { }) } -/// Whether `arg` is a `sbx run`/`check` option followed by a value. +/// Whether `arg` is an `insbx run`/`check` option followed by a value. fn takes_value(arg: &str) -> bool { matches!( arg, @@ -568,7 +568,7 @@ fn apply_flag(policy: &mut Policy, flag: &str, v: String) -> Result<(), String> if handled { Ok(()) } else { - Err(format!("unknown option `{flag}` (try `sbx --help`)")) + Err(format!("unknown option `{flag}` (try `insbx --help`)")) } } @@ -678,7 +678,7 @@ fn doctor() { enforcement(&p) }; println!( - "sbx {} on {}", + "insbx {} on {}", env!("CARGO_PKG_VERSION"), std::env::consts::OS ); diff --git a/crates/sandbox/src/policy.rs b/crates/sandbox/src/policy.rs index e26ea6d..7b866ac 100644 --- a/crates/sandbox/src/policy.rs +++ b/crates/sandbox/src/policy.rs @@ -138,7 +138,7 @@ pub struct Network { /// `localhost`, `127.0.0.1` or `::1` — a dev server a browser test loads, /// say. Only a loopback address is connected to, and nothing else private /// opens: `allow_private` stays as it is. The operator's setting alone: - /// `sbx mcp` gives an agent no way to ask for it. + /// `insbx mcp` gives an agent no way to ask for it. pub loopback_ports: Vec, } diff --git a/crates/sandbox/src/proxy.rs b/crates/sandbox/src/proxy.rs index 89c77ef..a08a9e6 100644 --- a/crates/sandbox/src/proxy.rs +++ b/crates/sandbox/src/proxy.rs @@ -274,7 +274,7 @@ impl Proxy { io::ErrorKind::AddrInUse, format!( "every port in {}-{} is taken (one per proxy run at once; \ - `sbx setup-windows --proxy-ports` widens the range)", + `insbx setup-windows --proxy-ports` widens the range)", ports.0, ports.1 ), ) @@ -403,7 +403,7 @@ fn serve( if !allowlist.allows(&head.host, head.port) { let reason = "not in network.allow".to_string(); - let _ = respond(&mut writer, 403, &format!("sbx: {target} is {reason}")); + let _ = respond(&mut writer, 403, &format!("insbx: {target} is {reason}")); return Some(Decision { target, allowed: false, @@ -422,7 +422,7 @@ fn serve( let mut server = match upstream_conn { Ok(s) => s, Err(reason) => { - let _ = respond(&mut writer, 502, &format!("sbx: {target}: {reason}")); + let _ = respond(&mut writer, 502, &format!("insbx: {target}: {reason}")); return Some(Decision { target, allowed: false, @@ -801,7 +801,7 @@ mod tests { } /// **A REFUSAL REACHES THE CLIENT WHILE PROCESSES ARE STARTED BESIDE - /// THE PROXY.** sbx starts the sandboxed command (and `icacls`) from the + /// THE PROXY.** insbx starts the sandboxed command (and `icacls`) from the /// process the proxy runs in. A socket the proxy cloned was inheritable /// on Windows, so a process started while a connection was open took a /// copy of it, and its exit reset the connection before the client had diff --git a/crates/sandbox/src/seccomp.rs b/crates/sandbox/src/seccomp.rs index 9c7ef1f..a2fa556 100644 --- a/crates/sandbox/src/seccomp.rs +++ b/crates/sandbox/src/seccomp.rs @@ -54,7 +54,7 @@ //! On aarch64, 32-bit ARM is checked with its own numbers. //! //! Not covered: `socketpair` (it only makes connected local pairs), sockets -//! and terminals passed in already open (`sbx` passes none but stdio; a +//! and terminals passed in already open (`insbx` passes none but stdio; a //! terminal on stdio can still be written to and read from, which is what //! a terminal is for), and name lookups a local daemon does on the //! command's behalf over a Unix socket: with `nss-resolve` diff --git a/crates/sandbox/src/server.rs b/crates/sandbox/src/server.rs index 26bfdd4..f150448 100644 --- a/crates/sandbox/src/server.rs +++ b/crates/sandbox/src/server.rs @@ -1,15 +1,15 @@ -//! `sbx mcp`: sandboxes as a service an agent drives over MCP (stdio). +//! `insbx mcp`: sandboxes as a service an agent drives over MCP (stdio). //! //! An agent creates a sandbox, writes scripts and files into it, runs them, //! reads what they produced, and throws it away. Every run happens under the -//! same policy machinery as `sbx run`: the command may write only inside its +//! same policy machinery as `insbx run`: the command may write only inside its //! sandbox's folder, sees the network only as the operator allowed, gets a //! cleaned environment, and is killed at its time limit along with anything //! it started. //! //! # Who decides what //! -//! The OPERATOR (whoever starts `sbx mcp`) sets the ceilings: how much +//! The OPERATOR (whoever starts `insbx mcp`) sets the ceilings: how much //! network a sandbox may ever have, which hosts, the longest a run may take. //! The AGENT (whoever sends the tool calls) chooses within them, and gets //! less by default: no network, no inherited secrets. A request above a @@ -84,7 +84,7 @@ impl Ceilings { impl Ceilings { /// The most a sandbox under these ceilings may ask for, as one policy: /// what a caller checks to know whether this machine can serve them - /// (`sbx.exe` choosing between native Windows and WSL2). + /// (`insbx.exe` choosing between native Windows and WSL2). #[must_use] pub fn widest_policy(&self) -> Policy { let mut p = self.base.clone(); @@ -167,7 +167,7 @@ impl Server { .and_then(Value::as_str) .unwrap_or("2025-06-18"), "capabilities": { "tools": {} }, - "serverInfo": { "name": "sbx", "version": env!("CARGO_PKG_VERSION") }, + "serverInfo": { "name": "insbx", "version": env!("CARGO_PKG_VERSION") }, "instructions": INSTRUCTIONS, }), "ping" => json!({}), @@ -210,7 +210,7 @@ impl Server { let (network, hosts) = self.requested_network(args)?; self.refuse_unenforceable(network)?; self.next += 1; - let id = format!("sbx-{}-{}", std::process::id(), self.next); + let id = format!("insbx-{}-{}", std::process::id(), self.next); let dir = self.ceilings.root.join(&id); std::fs::create_dir_all(&dir).map_err(|e| format!("{}: {e}", dir.display()))?; let dir = crate::plain_path(std::fs::canonicalize(&dir).map_err(|e| e.to_string())?); @@ -282,7 +282,7 @@ impl Server { Ok(()) } - /// On native Windows, where `deny` and `proxy` need `sbx setup-windows` + /// On native Windows, where `deny` and `proxy` need `insbx setup-windows` /// first, say so now rather than at every run, which would each be /// refused anyway. (Elsewhere enforcement depends on the kernel, and each /// run says.) @@ -431,7 +431,7 @@ impl Server { .unwrap_or(DEFAULT_INTERPRETER); let runs = self.boxes.get(&id).map_or(0, |b| b.runs) + 1; let (ext, _) = interpreter_style(interpreter, cfg!(windows)); - let name = format!(".sbx/script-{runs}{ext}"); + let name = format!(".insbx/script-{runs}{ext}"); let path = inside(&dir, &name, true)?; write_new(&path, script.as_bytes())?; script_argv(interpreter, &path.display().to_string(), cfg!(windows)) @@ -726,7 +726,7 @@ mod tests { .create(&json!({"network": "proxy", "allow_hosts": ["evil.example"]})) .is_err()); // Within the ceilings. Native Windows enforces proxy and deny only - // after `sbx setup-windows`, and without it says so at once instead. + // after `insbx setup-windows`, and without it says so at once instead. let mut deny = Policy::default(); deny.network.mode = NetMode::Deny; let unenforced = cfg!(windows) && crate::enforcement(&deny).network.is_gap(); @@ -746,12 +746,12 @@ mod tests { #[test] fn scripts_get_what_their_interpreter_needs_on_windows() { assert_eq!( - script_argv("sh", "/b/.sbx/script-1", false), - ["sh", "/b/.sbx/script-1"] + script_argv("sh", "/b/.insbx/script-1", false), + ["sh", "/b/.insbx/script-1"] ); assert_eq!(interpreter_style("powershell", false), ("", &[][..])); assert_eq!( - script_argv("powershell", r"C:\b\.sbx\script-1.ps1", true), + script_argv("powershell", r"C:\b\.insbx\script-1.ps1", true), [ "powershell", "-NoProfile", @@ -759,7 +759,7 @@ mod tests { "-ExecutionPolicy", "Bypass", "-File", - r"C:\b\.sbx\script-1.ps1" + r"C:\b\.insbx\script-1.ps1" ] ); assert_eq!(interpreter_style(r"C:\x\PWSH.EXE", true).0, ".ps1"); diff --git a/crates/sandbox/src/status.rs b/crates/sandbox/src/status.rs index b572fbe..4e8f033 100644 --- a/crates/sandbox/src/status.rs +++ b/crates/sandbox/src/status.rs @@ -1,6 +1,6 @@ //! What this machine enforces of a policy, part by part, before anything //! runs: [`enforcement`]. `Sandbox::command` refuses a policy with gaps in -//! strict mode; `sbx check` and `sbx doctor` print the same report. +//! strict mode; `insbx check` and `insbx doctor` print the same report. //! //! The platform answers come from `linux`, `windows` and, for macOS, the //! Seatbelt checks here. diff --git a/crates/sandbox/src/windows/acl.rs b/crates/sandbox/src/windows/acl.rs index bc15b64..b299619 100644 --- a/crates/sandbox/src/windows/acl.rs +++ b/crates/sandbox/src/windows/acl.rs @@ -1,7 +1,7 @@ //! The grant: one inheritable `Modify` ACE per writable root, for one run. //! //! Ported from incode's `sandbox::windows::acl`. incode grants once per -//! session and keeps the roots granted across commands; `sbx` runs one +//! session and keeps the roots granted across commands; `insbx` runs one //! command per policy, so each run gets its own SID and its own [`Lease`]: //! granted when the command is prepared, revoked when the lease drops after //! it exits. Two runs at once never share a SID, so neither can write the @@ -51,9 +51,9 @@ //! # A crash leaves the ACE behind: the sweep //! //! Every grant is written down before it is made, in -//! `%LOCALAPPDATA%\sbx\grants\.grant` (the SID and each root, and the +//! `%LOCALAPPDATA%\insbx\grants\.grant` (the SID and each root, and the //! account's SID and read paths), and the process holds a named mutex -//! `Global\sbx-grant-` while the lease lives. Every new lease first +//! `Global\insbx-grant-` while the lease lives. Every new lease first //! sweeps: a record whose mutex no longer exists belongs to a process that //! died, so its ACEs are revoked and the record deleted. A record whose //! revoke failed is kept for the next sweep. An ACE a dead run left is @@ -137,7 +137,7 @@ impl OfflineGrant { ) })?; } - // Only what this process may re-ACL: anything else (an sbx.exe under + // Only what this process may re-ACL: anything else (an insbx.exe under // Program Files) is the system's, readable by `Users` already or not // this run's to open up. If it is not readable, starting the command // says so. @@ -299,7 +299,7 @@ impl Lease { self.parents.push(parent.clone()); if let Err(e) = set_list(parent, user, true) { eprintln!( - "sbx: could not let the offline account list {} ({e}); PowerShell \ + "insbx: could not let the offline account list {} ({e}); PowerShell \ may start at the drive root instead of the current folder", parent.display() ); @@ -327,7 +327,7 @@ impl Drop for Lease { // (The temp directory may already be gone.) if let Err(e) = change(root, &self.record.sid, Change::Revoke) { eprintln!( - "sbx: could not revoke the sandbox's access to {} ({e}); the next run \ + "insbx: could not revoke the sandbox's access to {} ({e}); the next run \ sweeps it", root.display() ); @@ -345,7 +345,7 @@ impl Drop for Lease { { if let Err(e) = release_account(path, user, &others) { eprintln!( - "sbx: could not revoke the offline account's access to {} ({e}); the \ + "insbx: could not revoke the offline account's access to {} ({e}); the \ next run sweeps it", path.display() ); @@ -359,7 +359,7 @@ impl Drop for Lease { for parent in self.parents.iter().filter(|p| p.exists()) { if let Err(e) = release_list(parent, user, &others) { eprintln!( - "sbx: could not take back the offline account's listing of {} ({e}); \ + "insbx: could not take back the offline account's listing of {} ({e}); \ the next run sweeps it", parent.display() ); @@ -542,7 +542,7 @@ fn live_account_grants(own: &Path) -> Others { } /// Let the offline account read `path` (a folder and all beneath it, or one -/// file), for `sbx setup-windows --read`. +/// file), for `insbx setup-windows --read`. /// /// # Errors /// When the ACL cannot be read or written. @@ -609,8 +609,8 @@ pub(crate) fn owner_of(path: &Path) -> Result { /// refused). fn records_dir() -> PathBuf { std::env::var_os("LOCALAPPDATA") - .map(|d| PathBuf::from(d).join("sbx").join("grants")) - .unwrap_or_else(|| std::env::temp_dir().join("sbx-grants")) + .map(|d| PathBuf::from(d).join("insbx").join("grants")) + .unwrap_or_else(|| std::env::temp_dir().join("insbx-grants")) } /// A fresh RID nobody is using, and the liveness mutex that holds it. @@ -743,7 +743,7 @@ fn is_alive(rid: u32) -> bool { } fn alive_name(rid: u32) -> String { - format!("Global\\sbx-grant-{rid}") + format!("Global\\insbx-grant-{rid}") } #[derive(Clone, Copy)] @@ -1017,7 +1017,7 @@ impl AclLock { fn take() -> Result { // SAFETY: a NUL-terminated name; the handle is owned by the guard. unsafe { - let handle = CreateMutexW(std::ptr::null(), 0, wide("Global\\sbx-acl").as_ptr()); + let handle = CreateMutexW(std::ptr::null(), 0, wide("Global\\insbx-acl").as_ptr()); if handle.is_null() { return Err(last_error("CreateMutexW")); } diff --git a/crates/sandbox/src/windows/helper.rs b/crates/sandbox/src/windows/helper.rs index aa8fdc7..fc49c34 100644 --- a/crates/sandbox/src/windows/helper.rs +++ b/crates/sandbox/src/windows/helper.rs @@ -112,7 +112,7 @@ pub(crate) fn enter( if spec.strict { return Err(sandbox(format!("job object: {e}"))); } - eprintln!("sbx: job object limits not applied (best effort): {e}"); + eprintln!("insbx: job object limits not applied (best effort): {e}"); job(&JobLimits::from_limits(&crate::policy::Limits::default())) .map_err(|e| sandbox(format!("job object: {e}"))) })?; @@ -165,7 +165,7 @@ fn token_for(spec: &EnterSpec) -> Result, Failure> { spec.fs_mode.as_str() ))), Err(e) => { - eprintln!("sbx: restricted token not applied (best effort): {e}"); + eprintln!("insbx: restricted token not applied (best effort): {e}"); Ok(None) } } @@ -183,7 +183,7 @@ fn inner(spec: &EnterSpec, program: &OsString, args: &[OsString]) -> Result STARTUPINFOW { fn logon_failure(err: u32, account: &str, exe: &str) -> String { let why = match err { 1326 => format!( - "{account}'s password no longer matches the one sbx stored; run `sbx setup-windows` \ + "{account}'s password no longer matches the one insbx stored; run `insbx setup-windows` \ as administrator again" ), - 1331 => format!("{account} is disabled; run `sbx setup-windows` as administrator again"), + 1331 => format!("{account} is disabled; run `insbx setup-windows` as administrator again"), 1385 => format!("a policy denies {account} local logon (\"Allow log on locally\")"), 267 => format!("{account} cannot use the current folder"), 5 => format!("access denied (can {account} read {exe}?)"), @@ -395,7 +395,7 @@ fn confining_token(spec: &EnterSpec) -> Result { .as_deref() .ok_or("the helper was started without the run's SID")?; if !is_session_sid(sid) { - return Err(format!("{sid} is not an sbx run SID")); + return Err(format!("{sid} is not an insbx run SID")); } restricted(sid) } diff --git a/crates/sandbox/src/windows/mod.rs b/crates/sandbox/src/windows/mod.rs index 2891b4b..1d4157b 100644 --- a/crates/sandbox/src/windows/mod.rs +++ b/crates/sandbox/src/windows/mod.rs @@ -5,7 +5,7 @@ //! `windows/acl.rs`, Apache-2.0), whose authors measured it on Windows. What //! they measured is repeated here where it explains a choice. This crate's //! port is checked by `tests/escape_windows.rs` on the `windows-latest` CI -//! runner, after `sbx setup-windows` (see the README). +//! runner, after `insbx setup-windows` (see the README). //! //! # Writes: a write-restricted token //! @@ -48,7 +48,7 @@ //! the user's own SID would hide the path from the user everywhere, not just //! from the sandbox; a fully restricted token (not write-restricted) would //! need every file a toolchain reads granted to one of its SIDs. So -//! `deny_read` is reported not enforced, and `SBX_BACKEND=auto` sends such a +//! `deny_read` is reported not enforced, and `INSBX_BACKEND=auto` sends such a //! policy to WSL2, where Landlock enforces it. //! //! # Network: a second account the firewall cuts off ([`offline`]) @@ -57,8 +57,8 @@ //! all working under it). Only an AppContainer without the internet //! capabilities does, and an AppContainer reads only what is granted to it: //! the workspace, the user's toolchains and profile would all need granting. -//! Instead, once `sbx setup-windows` has run (elevated), `deny` and `proxy` -//! run the command as a local account, `sbx-offline`, that persistent +//! Instead, once `insbx setup-windows` has run (elevated), `deny` and `proxy` +//! run the command as a local account, `insbx-offline`, that persistent //! Windows Filtering Platform filters block from the network, as OpenAI //! Codex's Windows sandbox does. Without that setup they are reported not //! enforced, and `auto` sends them to WSL2. @@ -80,7 +80,7 @@ //! Git Bash and every msys program fail to start under the write-restricted //! token: the msys runtime maps a per-user shared section the token may not //! map writable, and dies with `CreateFileMapping ..., Win32 error 5` -//! (incode measured). Use `cmd` or PowerShell, or `SBX_BACKEND=wsl` for a +//! (incode measured). Use `cmd` or PowerShell, or `INSBX_BACKEND=wsl` for a //! POSIX shell. // The pure parts below are compiled on every platform so their tests run in @@ -105,7 +105,7 @@ mod token; #[cfg(windows)] pub(crate) use helper::enter; -/// `sbx setup-windows` (or `--remove`): what it did, line by line. +/// `insbx setup-windows` (or `--remove`): what it did, line by line. /// /// # Errors /// When not elevated, or a step fails. @@ -164,7 +164,7 @@ pub fn default_dacl_sddl(user_sid: &str, run_sid: &str) -> String { /// Why `deny_read` is not enforced natively. pub const DENY_READ_NOT_ENFORCED: &str = "a write-restricted token consults its restricting SIDs only for writes, so no ACE can hide \ - a path from the sandbox alone; use WSL2 (SBX_BACKEND=wsl, or auto), where Landlock does"; + a path from the sandbox alone; use WSL2 (INSBX_BACKEND=wsl, or auto), where Landlock does"; /// What native Windows enforces of the filesystem policy. #[must_use] @@ -659,7 +659,7 @@ impl JobLimits { /// time, the one whose call arrives while the other's start of seclogon is /// still in progress is refused with this error instead of waiting for it — /// and its command is not run. Observed on the `windows-latest` runner -/// (`sbx: the command could not be started as sbx-offline … Win32 error +/// (`insbx: the command could not be started as insbx-offline … Win32 error /// 1056`), in the escape tests that start several network-deny runs at once /// right after `setup-windows`; the race is inferred from that, not /// reproduced on a machine where seclogon was already up. @@ -765,7 +765,7 @@ mod tests { &format!("{SID_PREFIX}007"), &format!("{SID_PREFIX}12-5"), &format!("{SID_PREFIX}99999999999"), - // incode's own prefix: never swept or used by sbx. + // incode's own prefix: never swept or used by insbx. "S-1-5-21-1111111111-2222222222-3333333333-77", ] { assert!(!is_session_sid(bad), "{bad}"); @@ -798,7 +798,10 @@ mod tests { sid: session_sid(9), roots, user: Some("S-1-5-21-1-2-3-1009".into()), - reads: vec![PathBuf::from(r"C:\proj"), PathBuf::from(r"C:\bin\sbx.exe")], + reads: vec![ + PathBuf::from(r"C:\proj"), + PathBuf::from(r"C:\bin\insbx.exe"), + ], parents: vec![PathBuf::from(r"C:\Users\me\src")], }; assert!(offline.to_text().ends_with("parent C:\\Users\\me\\src\n")); @@ -814,11 +817,11 @@ mod tests { #[test] fn a_record_from_before_the_parent_lines_still_parses() { let text = format!( - "sid {}\nroot C:\\w\nuser S-1-5-21-1-2-3-1009\nread C:\\bin\\sbx.exe\n", + "sid {}\nroot C:\\w\nuser S-1-5-21-1-2-3-1009\nread C:\\bin\\insbx.exe\n", session_sid(7) ); let record = GrantRecord::parse(&text).expect("parses"); - assert_eq!(record.reads, [PathBuf::from(r"C:\bin\sbx.exe")]); + assert_eq!(record.reads, [PathBuf::from(r"C:\bin\insbx.exe")]); assert!(record.parents.is_empty()); // And written back, it is the same text: nothing new appears. assert_eq!(record.to_text(), text); @@ -922,7 +925,7 @@ mod tests { assert!(holds(r"\\?\C:\Users\Me", r"C:\Users\me")); assert!(!holds(r"C:\Users\me", r"C:\Users\meta")); assert!(holds(r"C:\", r"C:\anything")); - assert_eq!(strip_verbatim(r"\\?\C:\t\sbx-1"), r"C:\t\sbx-1"); + assert_eq!(strip_verbatim(r"\\?\C:\t\insbx-1"), r"C:\t\insbx-1"); assert_eq!(strip_verbatim(r"\\?\UNC\srv\s\x"), r"\\srv\s\x"); assert_eq!(strip_verbatim(r"C:\t"), r"C:\t"); } @@ -941,7 +944,7 @@ mod tests { assert!(refuse_broad(broad, profile).is_err(), "{broad}"); } assert!(refuse_broad(r"C:\Users\someone\proj", profile).is_ok()); - assert!(refuse_broad(r"\\?\C:\Users\someone\AppData\Local\Temp\sbx-1", profile).is_ok()); + assert!(refuse_broad(r"\\?\C:\Users\someone\AppData\Local\Temp\insbx-1", profile).is_ok()); assert!(refuse_broad(r"\\server\share\proj", profile).is_ok()); let folded = fold_nested(&[ PathBuf::from(r"C:\w\a\inner"), @@ -956,24 +959,24 @@ mod tests { fn the_offline_account_reads_the_current_folder_and_helper_unless_granted_already() { let roots = [ PathBuf::from(r"\\?\C:\w\proj"), - PathBuf::from(r"C:\t\sbx-1"), + PathBuf::from(r"C:\t\insbx-1"), ]; - let helper = Path::new(r"C:\tools\sbx.exe"); + let helper = Path::new(r"C:\tools\insbx.exe"); assert_eq!( offline_reads(&roots, Path::new(r"C:\w\proj\sub"), helper), - [PathBuf::from(r"C:\tools\sbx.exe")] + [PathBuf::from(r"C:\tools\insbx.exe")] ); assert_eq!( offline_reads( &roots, Path::new(r"C:\w"), - Path::new(r"c:\W\PROJ\target\sbx.exe") + Path::new(r"c:\W\PROJ\target\insbx.exe") ), [PathBuf::from(r"C:\w")] ); assert_eq!( offline_reads(&[], Path::new(r"C:\w"), helper), - [PathBuf::from(r"C:\w"), PathBuf::from(r"C:\tools\sbx.exe")] + [PathBuf::from(r"C:\w"), PathBuf::from(r"C:\tools\insbx.exe")] ); } @@ -1073,7 +1076,7 @@ mod tests { let ready = Ok(offline::Ready { sid: "S-1-5-21-1-1009".into(), proxy_ports: offline::DEFAULT_PROXY_PORTS, - record: PathBuf::from(r"C:\ProgramData\sbx\offline.conf"), + record: PathBuf::from(r"C:\ProgramData\insbx\offline.conf"), }); assert!(!net_status(NetMode::Deny, &ready).is_gap()); assert!(!net_status(NetMode::Proxy, &ready).is_gap()); diff --git a/crates/sandbox/src/windows/offline.rs b/crates/sandbox/src/windows/offline.rs index a9aeccb..21af891 100644 --- a/crates/sandbox/src/windows/offline.rs +++ b/crates/sandbox/src/windows/offline.rs @@ -7,14 +7,14 @@ //! (`codex-rs/windows-sandbox-rs`, Apache-2.0: `setup_provisioning/ //! sandbox_users.rs`, `setup_provisioning/firewall.rs`, `wfp.rs`, `dpapi.rs`, //! `elevated/runner_client.rs`), a one-time elevated setup -//! (`sbx setup-windows`): +//! (`insbx setup-windows`): //! //! 1. creates a local account, [`ACCOUNT`], member of `Users` only (it needs //! `Users` to log on locally and to read `C:\Windows` and `Program Files`; //! Codex adds its accounts to `Users` too), with a random password nobody //! is shown, hidden from the sign-in screen; //! 2. stores that password DPAPI-protected (machine scope) in a record under -//! `%ProgramData%\sbx`, readable by SYSTEM, Administrators and the user who +//! `%ProgramData%\insbx`, readable by SYSTEM, Administrators and the user who //! ran the setup only ([`state_dir_sddl`]); //! 3. adds persistent WFP filters ([`FILTERS`]) that block every connection //! the account makes or accepts, TCP, UDP and ICMP, loopback included, and @@ -38,13 +38,13 @@ //! what the user may: system folders, and what each run grants it (the //! writable roots, the current folder, the helper program, the private //! temp directory). A toolchain under the user's profile must be granted -//! once with `sbx setup-windows --read `. Narrower, never wider. +//! once with `insbx setup-windows --read `. Narrower, never wider. //! - **Writes** need both the account (the token's normal check) and the //! run's SID (its restricted check): each root gets an ACE for each. The //! account's ACE is shared by concurrent runs, so it is only revoked when //! no other live run still needs it ([`still_needed`]). //! - **No profile is loaded** (`dwLogonFlags = 0`, as Codex's runner does): -//! loading it would create `C:\Users\sbx-offline` on first use, a home every +//! loading it would create `C:\Users\insbx-offline` on first use, a home every //! run shares and could leave things in for the next. The command gets the //! run's computed environment instead. //! @@ -64,11 +64,11 @@ use crate::policy::NetMode; use crate::Status; /// The local account commands run as when the network is denied. -pub const ACCOUNT: &str = "sbx-offline"; +pub const ACCOUNT: &str = "insbx-offline"; /// The account's description, shown in Computer Management. pub const ACCOUNT_COMMENT: &str = - "sbx: runs sandboxed commands with no network (made by sbx setup-windows)"; + "insbx: runs sandboxed commands with no network (made by insbx setup-windows)"; /// The loopback ports a `proxy` run's proxy may listen on, one per /// concurrent run. Below Windows' dynamic range (49152-65535), so the system @@ -76,19 +76,19 @@ pub const ACCOUNT_COMMENT: &str = pub const DEFAULT_PROXY_PORTS: (u16, u16) = (47_600, 47_615); /// The folder under `%ProgramData%` that holds the record. -pub const STATE_DIR: &str = "sbx"; +pub const STATE_DIR: &str = "insbx"; /// The record's file name. pub const RECORD_FILE: &str = "offline.conf"; /// DPAPI's optional entropy: the blob is useless to anything that does not /// also know this, which keeps a generic "decrypt every machine blob" tool /// from reading it in passing. The file's ACL is the protection. -pub const DPAPI_ENTROPY: &[u8] = b"sbx-offline-v1"; +pub const DPAPI_ENTROPY: &[u8] = b"insbx-offline-v1"; -const RECORD_MAGIC: &str = "sbx-offline-record"; +const RECORD_MAGIC: &str = "insbx-offline-record"; const RECORD_VERSION: u32 = 1; -/// What `sbx setup-windows` wrote down. +/// What `insbx setup-windows` wrote down. #[derive(Debug, Clone, PartialEq, Eq)] pub struct Record { /// The account name ([`ACCOUNT`]). @@ -137,10 +137,10 @@ impl Record { Some((RECORD_MAGIC, v)) if v.trim() == RECORD_VERSION.to_string() => {} Some((RECORD_MAGIC, v)) => { return Err(format!( - "the record is version {v}; this sbx reads version {RECORD_VERSION}" + "the record is version {v}; this insbx reads version {RECORD_VERSION}" )) } - _ => return Err("not an sbx offline record".to_string()), + _ => return Err("not an insbx offline record".to_string()), } let (mut account, mut sid, mut owner, mut ports, mut password) = (None, None, None, None, None); @@ -358,7 +358,7 @@ const IPPROTO_ICMPV6: u8 = 58; pub const FILTERS: &[FilterSpec] = &[ FilterSpec { key: 0x41ae_b76d_b1c6_46e2_a8ec_2773_5b76_7fb3, - name: "sbx_offline_block_connect_v4", + name: "insbx_offline_block_connect_v4", layer: Layer::ConnectV4, permit: false, weight: 1, @@ -366,7 +366,7 @@ pub const FILTERS: &[FilterSpec] = &[ }, FilterSpec { key: 0x1933_8d8b_ba7f_4fbd_aa2d_ac85_c850_0a44, - name: "sbx_offline_block_connect_v6", + name: "insbx_offline_block_connect_v6", layer: Layer::ConnectV6, permit: false, weight: 1, @@ -374,7 +374,7 @@ pub const FILTERS: &[FilterSpec] = &[ }, FilterSpec { key: 0x992a_71cd_6ae4_49d0_a019_245c_7fe3_cc39, - name: "sbx_offline_block_accept_v4", + name: "insbx_offline_block_accept_v4", layer: Layer::AcceptV4, permit: false, weight: 1, @@ -382,7 +382,7 @@ pub const FILTERS: &[FilterSpec] = &[ }, FilterSpec { key: 0xf187_fa38_db37_4fd8_874d_6df8_c8ef_6b78, - name: "sbx_offline_block_accept_v6", + name: "insbx_offline_block_accept_v6", layer: Layer::AcceptV6, permit: false, weight: 1, @@ -392,7 +392,7 @@ pub const FILTERS: &[FilterSpec] = &[ // blocked at connect anyway. FilterSpec { key: 0x9124_0db3_5eea_4a0d_be98_364b_aa57_e626, - name: "sbx_offline_block_icmp_v4", + name: "insbx_offline_block_icmp_v4", layer: Layer::AssignV4, permit: false, weight: 1, @@ -400,7 +400,7 @@ pub const FILTERS: &[FilterSpec] = &[ }, FilterSpec { key: 0xb436_7d8e_cbdc_4ded_8b82_d6e4_350b_daee, - name: "sbx_offline_block_icmp_v6", + name: "insbx_offline_block_icmp_v6", layer: Layer::AssignV6, permit: false, weight: 1, @@ -408,7 +408,7 @@ pub const FILTERS: &[FilterSpec] = &[ }, FilterSpec { key: 0x4deb_7adf_bcc1_442f_aad6_b1b7_d307_a302, - name: "sbx_offline_permit_proxy_v4", + name: "insbx_offline_permit_proxy_v4", layer: Layer::ConnectV4, permit: true, weight: 15, @@ -424,9 +424,9 @@ pub const FILTERS: &[FilterSpec] = &[ /// The filter whose presence says the setup is in place. pub const MAIN_FILTER: &FilterSpec = &FILTERS[0]; -// ---- `sbx setup-windows`'s arguments. ---- +// ---- `insbx setup-windows`'s arguments. ---- -/// What `sbx setup-windows` was asked to do. +/// What `insbx setup-windows` was asked to do. #[derive(Debug, Clone, PartialEq, Eq, Default)] pub struct SetupArgs { /// `--remove`: undo everything. @@ -437,7 +437,7 @@ pub struct SetupArgs { pub proxy_ports: Option<(u16, u16)>, } -/// Parse `sbx setup-windows`'s arguments. +/// Parse `insbx setup-windows`'s arguments. /// /// # Errors /// For an unknown option, a missing value, or `--remove` with anything else. @@ -463,7 +463,7 @@ pub fn parse_setup_args(args: &[String]) -> Result { } other => { return Err(format!( - "sbx setup-windows: unknown option `{other}` (--remove, --read , \ + "insbx setup-windows: unknown option `{other}` (--remove, --read , \ --proxy-ports )" )) } @@ -471,7 +471,7 @@ pub fn parse_setup_args(args: &[String]) -> Result { i += 1; } if out.remove && (!out.reads.is_empty() || out.proxy_ports.is_some()) { - return Err("sbx setup-windows --remove takes no other option".to_string()); + return Err("insbx setup-windows --remove takes no other option".to_string()); } Ok(out) } @@ -490,16 +490,16 @@ pub struct Ready { } /// How to get layer 2, for messages. -pub const SETUP_HINT: &str = "run `sbx setup-windows` as administrator once (it creates the \ - offline account sbx-offline and its firewall filters), or use WSL2 (SBX_BACKEND=wsl, or auto)"; +pub const SETUP_HINT: &str = "run `insbx setup-windows` as administrator once (it creates the \ + offline account insbx-offline and its firewall filters), or use WSL2 (INSBX_BACKEND=wsl, or auto)"; /// What native Windows enforces of the network policy, given whether the /// setup is in place (`Err` says why not). #[must_use] pub fn net_status(mode: NetMode, setup: &Result) -> Status { - let reads = "the command runs as the local account sbx-offline and so reads only what that \ + let reads = "the command runs as the local account insbx-offline and so reads only what that \ account may: system folders, the run's roots, current folder and temp \ - directory, and folders granted with `sbx setup-windows --read`"; + directory, and folders granted with `insbx setup-windows --read`"; match (mode, setup) { (NetMode::Allow, _) => Status::NotRequested, (NetMode::Deny, Ok(_)) => Status::Enforced(format!( @@ -571,7 +571,7 @@ mod tests { fn a_record_round_trips() { let r = record(); let text = r.to_text(); - assert!(text.starts_with("sbx-offline-record 1\n"), "{text}"); + assert!(text.starts_with("insbx-offline-record 1\n"), "{text}"); assert!(text.contains("password 0001abff\n"), "{text}"); assert!(text.contains("proxy-ports 47600-47615\n"), "{text}"); assert_eq!(Record::parse(&text), Ok(r)); @@ -594,7 +594,7 @@ mod tests { ("password 0001abff", "password xyz"), ("password 0001abff", "password abc"), ("proxy-ports 47600-47615", "proxy-ports 9-1"), - ("account sbx-offline", "account "), + ("account insbx-offline", "account "), ] { let bad = record().to_text().replace(from, to); assert!(Record::parse(&bad).is_err(), "{to}"); @@ -665,7 +665,7 @@ mod tests { names.dedup(); assert_eq!(names.len(), FILTERS.len()); for f in FILTERS { - assert!(f.name.starts_with("sbx_offline_"), "{}", f.name); + assert!(f.name.starts_with("insbx_offline_"), "{}", f.name); assert!(f.conditions.contains(&Cond::User), "{} is per-user", f.name); assert!(f.weight <= 15); } @@ -728,11 +728,11 @@ mod tests { let ready = Ok(Ready { sid: "S-1-5-21-1-1009".into(), proxy_ports: (5000, 5003), - record: PathBuf::from(r"C:\ProgramData\sbx\offline.conf"), + record: PathBuf::from(r"C:\ProgramData\insbx\offline.conf"), }); assert_eq!(net_status(NetMode::Allow, &ready), Status::NotRequested); assert!( - matches!(net_status(NetMode::Deny, &ready), Status::Enforced(s) if s.contains("sbx-offline") && s.contains("loopback")) + matches!(net_status(NetMode::Deny, &ready), Status::Enforced(s) if s.contains("insbx-offline") && s.contains("loopback")) ); assert!( matches!(net_status(NetMode::Proxy, &ready), Status::Enforced(s) if s.contains("5000-5003")) @@ -741,7 +741,7 @@ mod tests { for mode in [NetMode::Deny, NetMode::Proxy] { let st = net_status(mode, &missing); assert!( - matches!(&st, Status::NotEnforced(s) if s.contains("sbx setup-windows` as administrator") && s.contains("not set up")), + matches!(&st, Status::NotEnforced(s) if s.contains("insbx setup-windows` as administrator") && s.contains("not set up")), "{st:?}" ); } diff --git a/crates/sandbox/src/windows/setup.rs b/crates/sandbox/src/windows/setup.rs index 2444571..6275c79 100644 --- a/crates/sandbox/src/windows/setup.rs +++ b/crates/sandbox/src/windows/setup.rs @@ -1,4 +1,4 @@ -//! `sbx setup-windows`: the offline account, its password, and the WFP +//! `insbx setup-windows`: the offline account, its password, and the WFP //! filters that cut it off ([`super::offline`] says why each is so); and, //! at run time, finding them ([`ready`]) and reading the password //! ([`password`]). @@ -83,7 +83,7 @@ const SYSTEM: &str = "S-1-5-18"; const USERLIST_KEY: &str = r"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList"; -const NEEDS_ELEVATION: &str = "sbx setup-windows changes the machine (a local account and \ +const NEEDS_ELEVATION: &str = "insbx setup-windows changes the machine (a local account and \ firewall filters) and needs administrator rights: run it from an elevated prompt \ (right-click your terminal, Run as administrator)"; @@ -217,7 +217,7 @@ fn blob(bytes: &[u8]) -> CRYPT_INTEGER_BLOB { // ---- Where things are. ---- -/// `%ProgramData%\sbx`. From the environment the parent was started with +/// `%ProgramData%\insbx`. From the environment the parent was started with /// (a user who points it elsewhere only misleads their own runs). pub(crate) fn state_dir() -> PathBuf { let base = std::env::var_os("ProgramData") @@ -388,7 +388,7 @@ pub(crate) fn password(path: &Path) -> Result<(String, Secret), String> { // ---- Setup. ---- -/// Run `sbx setup-windows` (or `--remove`): what it did, line by line. +/// Run `insbx setup-windows` (or `--remove`): what it did, line by line. /// /// # Errors /// When not elevated, or a step fails (said which). @@ -720,7 +720,7 @@ fn hide_from_sign_in(hide: bool) -> Result<(), String> { Ok(()) } -/// `%ProgramData%\sbx` with the record's ACL, then the record in it, +/// `%ProgramData%\insbx` with the record's ACL, then the record in it, /// replacing any old one. fn write_record(record: &Record) -> Result<(), String> { let dir = state_dir(); @@ -855,7 +855,7 @@ impl Engine { // SAFETY: a zeroed session is the documented default; a // NUL-terminated name that lives across the call. unsafe { - let name = wide("sbx setup-windows"); + let name = wide("insbx setup-windows"); let mut session: FWPM_SESSION0 = std::mem::zeroed(); session.displayData.name = name.as_ptr().cast_mut(); session.txnWaitTimeoutInMSec = wait_ms; @@ -933,8 +933,8 @@ fn install_filters(account_sid: &str, ports: (u16, u16)) -> Result<(), String> { let user_sd_len = unsafe { GetSecurityDescriptorLength(user_sd.0) }; let provider_key = guid(PROVIDER_KEY); let sublayer_key = guid(SUBLAYER_KEY); - let name = wide("sbx offline account"); - let description = wide("sbx setup-windows: the sbx-offline account has no network"); + let name = wide("insbx offline account"); + let description = wide("insbx setup-windows: the insbx-offline account has no network"); engine.transaction(|| { // SAFETY: every structure passed points at locals that outlive the // calls (names, keys, the descriptor blob, the range); WFP copies diff --git a/crates/sandbox/src/wslpath.rs b/crates/sandbox/src/wslpath.rs index 1f80b22..53de3d4 100644 --- a/crates/sandbox/src/wslpath.rs +++ b/crates/sandbox/src/wslpath.rs @@ -1,4 +1,4 @@ -//! Windows paths as WSL sees them, for `sbx.exe` forwarding a command into +//! Windows paths as WSL sees them, for `insbx.exe` forwarding a command into //! WSL2 (where the Linux sandbox does the confining). //! //! `C:\work\app` is `/mnt/c/work/app` in WSL's default mount layout @@ -35,7 +35,7 @@ pub fn to_wsl(path: &str) -> Option { None } -/// The options of `sbx` whose value is a path. +/// The options of `insbx` whose value is a path. pub const PATH_OPTIONS: &[&str] = &[ "-w", "--write", @@ -46,7 +46,7 @@ pub const PATH_OPTIONS: &[&str] = &[ "--root", ]; -/// `sbx` arguments rewritten for WSL: each path option's value, and any +/// `insbx` arguments rewritten for WSL: each path option's value, and any /// argument after `--` that is a drive path (`C:\...`), translated. /// /// # Errors diff --git a/crates/sandbox/tests/escape.rs b/crates/sandbox/tests/escape.rs index 338729d..f2987be 100644 --- a/crates/sandbox/tests/escape.rs +++ b/crates/sandbox/tests/escape.rs @@ -1,5 +1,5 @@ //! Escape tests: each one tries to get out of the sandbox the way a confused -//! or hostile command would, through the real `sbx` binary. +//! or hostile command would, through the real `insbx` binary. //! //! Linux only, and each test skips (with a note) when the kernel cannot //! enforce what it checks, so a machine without Landlock reports a skip @@ -13,22 +13,22 @@ use std::path::Path; use std::process::{Command, Output, Stdio}; use std::time::{Duration, Instant}; -const SBX: &str = env!("CARGO_BIN_EXE_sbx"); +const INSBX: &str = env!("CARGO_BIN_EXE_insbx"); -fn sbx(args: &[&str], cwd: &Path) -> Output { - Command::new(SBX) +fn insbx(args: &[&str], cwd: &Path) -> Output { + Command::new(INSBX) .args(args) .current_dir(cwd) .stdin(Stdio::null()) .output() - .expect("sbx runs") + .expect("insbx runs") } fn sh(cwd: &Path, flags: &[&str], script: &str) -> Output { let mut args = vec!["run"]; args.extend_from_slice(flags); args.extend_from_slice(&["--", "sh", "-c", script]); - sbx(&args, cwd) + insbx(&args, cwd) } fn text(o: &Output) -> String { @@ -40,7 +40,7 @@ fn text(o: &Output) -> String { } fn landlock_fs() -> bool { - let o = Command::new(SBX) + let o = Command::new(INSBX) .args(["check", "--fs", "workspace-write"]) .output() .expect("check"); @@ -48,7 +48,7 @@ fn landlock_fs() -> bool { } fn landlock_net() -> bool { - Command::new(SBX) + Command::new(INSBX) .args(["check", "--net", "deny"]) .output() .expect("check") @@ -132,7 +132,7 @@ fn symlinks_hardlinks_renames_and_proc_root_do_not_escape() { fn temp_is_private_and_shared_tmp_is_not_writable() { require!(landlock_fs(), "the filesystem"); let d = dirs(); - let marker = std::env::temp_dir().join(format!("sbx-escape-{}", std::process::id())); + let marker = std::env::temp_dir().join(format!("insbx-escape-{}", std::process::id())); let o = sh( &d.ws, &["-w", "."], @@ -142,7 +142,7 @@ fn temp_is_private_and_shared_tmp_is_not_writable() { ), ); let out = text(&o); - assert!(out.contains("sbx-"), "TMPDIR is the private one: {out}"); + assert!(out.contains("insbx-"), "TMPDIR is the private one: {out}"); assert!(!marker.exists(), "wrote to the shared temp dir"); } @@ -216,7 +216,7 @@ fn network_deny_refuses_connect_and_bind_even_on_loopback() { "exec 3<>/dev/tcp/127.0.0.1/{port} 2>/dev/null && echo connected; \ python3 -c 'import socket;socket.socket().bind((\"127.0.0.1\",0));print(\"bound\")' 2>/dev/null" ); - let o = sbx( + let o = insbx( &["run", "--net", "deny", "--", "bash", "-c", &script], &d.ws, ); @@ -298,7 +298,7 @@ fn a_udp_socket_works_when_the_network_is_allowed() { fn dns_lookups_fail_under_deny() { require!(landlock_net(), "the network (Landlock ABI v4 and seccomp)"); // A lookup a local daemon answers over a Unix socket is not network - // access sbx can see (README, known limits); this checks plain DNS. + // access insbx can see (README, known limits); this checks plain DNS. let nss = std::fs::read_to_string("/etc/nsswitch.conf").unwrap_or_default(); let hosts = nss .lines() @@ -346,7 +346,7 @@ fn the_proxy_lets_through_only_the_allowlist_and_cannot_be_bypassed() { ); // The test origin is on loopback, so private answers must be allowed, // and this process's own upstream proxy (if any) must not be used. - let o = Command::new(SBX) + let o = Command::new(INSBX) .args([ "run", "--allow-host", @@ -364,10 +364,10 @@ fn the_proxy_lets_through_only_the_allowlist_and_cannot_be_bypassed() { .env_remove("http_proxy") .stdin(Stdio::null()) .output() - .expect("sbx"); + .expect("insbx"); let out = text(&o); assert!(out.contains("allowed=origin"), "{out}"); - assert!(out.contains("other=sbx: 127.0.0.1"), "{out}"); + assert!(out.contains("other=insbx: 127.0.0.1"), "{out}"); assert!( out.contains("bypass=\n"), "the direct connection got through: {out}" @@ -378,7 +378,7 @@ fn the_proxy_lets_through_only_the_allowlist_and_cannot_be_bypassed() { #[test] fn the_agent_session_and_git_redirects_are_stripped_and_credentials_kept() { let d = dirs(); - let o = Command::new(SBX) + let o = Command::new(INSBX) .args([ "run", "--", @@ -392,17 +392,17 @@ fn the_agent_session_and_git_redirects_are_stripped_and_credentials_kept() { .env("GIT_DIR", "/elsewhere/.git") .env("ANTHROPIC_API_KEY", "key") .output() - .expect("sbx"); + .expect("insbx"); assert_eq!(String::from_utf8_lossy(&o.stdout).trim(), "[][][][key]"); } #[test] fn the_wall_limit_kills_the_whole_group() { let d = dirs(); - let tag = format!("sbx_wall_{}", std::process::id()); + let tag = format!("insbx_wall_{}", std::process::id()); let start = Instant::now(); let script = format!("(exec -a {tag} sleep 30) & (exec -a {tag} sleep 30)"); - let o = sbx(&["run", "--wall", "1", "--", "bash", "-c", &script], &d.ws); + let o = insbx(&["run", "--wall", "1", "--", "bash", "-c", &script], &d.ws); assert_eq!(o.status.code(), Some(124), "{}", text(&o)); assert!(start.elapsed() < Duration::from_secs(10)); std::thread::sleep(Duration::from_millis(300)); @@ -410,10 +410,10 @@ fn the_wall_limit_kills_the_whole_group() { } #[test] -fn killing_sbx_with_sigkill_takes_the_command_with_it() { +fn killing_insbx_with_sigkill_takes_the_command_with_it() { let d = dirs(); - let tag = format!("sbx_orphan_{}", std::process::id()); - let mut child = Command::new(SBX) + let tag = format!("insbx_orphan_{}", std::process::id()); + let mut child = Command::new(INSBX) .args([ "run", "--wall", @@ -426,7 +426,7 @@ fn killing_sbx_with_sigkill_takes_the_command_with_it() { .current_dir(&d.ws) .stdin(Stdio::null()) .spawn() - .expect("sbx"); + .expect("insbx"); let deadline = Instant::now() + Duration::from_secs(5); while !running(&tag) && Instant::now() < deadline { std::thread::sleep(Duration::from_millis(50)); @@ -438,7 +438,7 @@ fn killing_sbx_with_sigkill_takes_the_command_with_it() { while running(&tag) && Instant::now() < deadline { std::thread::sleep(Duration::from_millis(50)); } - assert!(!running(&tag), "the command outlived sbx"); + assert!(!running(&tag), "the command outlived insbx"); } #[test] @@ -454,9 +454,9 @@ fn limits_and_exit_codes() { std::fs::metadata(d.ws.join("big")).expect("big").len(), 1024 * 1024 ); - let o = sbx(&["run", "--", "no-such-command-sbx"], &d.ws); + let o = insbx(&["run", "--", "no-such-command-insbx"], &d.ws); assert_eq!(o.status.code(), Some(127)); - let o = sbx(&["run", "-w", "missing-root", "--", "true"], &d.ws); + let o = insbx(&["run", "-w", "missing-root", "--", "true"], &d.ws); assert_eq!(o.status.code(), Some(125)); } @@ -472,7 +472,7 @@ fn running(tag: &str) -> bool { }) } -/// Whether `sbx` has a seccomp filter for this architecture. +/// Whether `insbx` has a seccomp filter for this architecture. const SECCOMP_ARCH: bool = cfg!(any(target_arch = "x86_64", target_arch = "aarch64")); /// In a new session, makes a pty's slave its controlling terminal, then diff --git a/crates/sandbox/tests/escape_macos.rs b/crates/sandbox/tests/escape_macos.rs index aa7613c..1a7b8cb 100644 --- a/crates/sandbox/tests/escape_macos.rs +++ b/crates/sandbox/tests/escape_macos.rs @@ -1,5 +1,5 @@ //! Escape tests against Seatbelt: the Linux escape tests that apply on -//! macOS, through the real `sbx` binary. +//! macOS, through the real `insbx` binary. //! //! They use only what a stock Mac (and the macOS CI runner) has: `sh`, //! `bash`, `nc`, `curl`, `ps`. Each test skips (with a note) when @@ -14,22 +14,22 @@ use std::path::{Path, PathBuf}; use std::process::{Command, Output, Stdio}; use std::time::{Duration, Instant}; -const SBX: &str = env!("CARGO_BIN_EXE_sbx"); +const INSBX: &str = env!("CARGO_BIN_EXE_insbx"); -fn sbx(args: &[&str], cwd: &Path) -> Output { - Command::new(SBX) +fn insbx(args: &[&str], cwd: &Path) -> Output { + Command::new(INSBX) .args(args) .current_dir(cwd) .stdin(Stdio::null()) .output() - .expect("sbx runs") + .expect("insbx runs") } fn sh(cwd: &Path, flags: &[&str], script: &str) -> Output { let mut args = vec!["run"]; args.extend_from_slice(flags); args.extend_from_slice(&["--", "sh", "-c", script]); - sbx(&args, cwd) + insbx(&args, cwd) } fn text(o: &Output) -> String { @@ -43,7 +43,7 @@ fn text(o: &Output) -> String { fn enforced(flags: &[&str]) -> bool { let mut args = vec!["check"]; args.extend_from_slice(flags); - Command::new(SBX) + Command::new(INSBX) .args(&args) .output() .expect("check") @@ -132,7 +132,7 @@ fn symlinks_and_child_processes_do_not_escape() { fn temp_is_private_and_the_shared_temp_dir_is_not_writable() { require!(FS, "the filesystem"); let d = dirs(); - let marker = std::env::temp_dir().join(format!("sbx-escape-{}", std::process::id())); + let marker = std::env::temp_dir().join(format!("insbx-escape-{}", std::process::id())); let o = sh( &d.ws, &["-w", "."], @@ -142,7 +142,7 @@ fn temp_is_private_and_the_shared_temp_dir_is_not_writable() { ), ); let out = text(&o); - assert!(out.contains("sbx-"), "TMPDIR is the private one: {out}"); + assert!(out.contains("insbx-"), "TMPDIR is the private one: {out}"); assert!(!marker.exists(), "wrote to the shared temp dir"); } @@ -255,7 +255,7 @@ fn the_proxy_lets_through_only_the_allowlist_and_cannot_be_bypassed() { ); // The test origin is on loopback, so private answers must be allowed, // and this process's own upstream proxy (if any) must not be used. - let o = Command::new(SBX) + let o = Command::new(INSBX) .args([ "run", "--allow-host", @@ -273,10 +273,10 @@ fn the_proxy_lets_through_only_the_allowlist_and_cannot_be_bypassed() { .env_remove("http_proxy") .stdin(Stdio::null()) .output() - .expect("sbx"); + .expect("insbx"); let out = text(&o); assert!(out.contains("allowed=origin"), "{out}"); - assert!(out.contains("other=sbx: 127.0.0.1"), "{out}"); + assert!(out.contains("other=insbx: 127.0.0.1"), "{out}"); assert!( out.contains("bypass=\n"), "the direct connection got through: {out}" @@ -288,7 +288,7 @@ fn the_proxy_lets_through_only_the_allowlist_and_cannot_be_bypassed() { #[test] fn the_agent_session_and_git_redirects_are_stripped_and_credentials_kept() { let d = dirs(); - let o = Command::new(SBX) + let o = Command::new(INSBX) .args([ "run", "--", @@ -302,17 +302,17 @@ fn the_agent_session_and_git_redirects_are_stripped_and_credentials_kept() { .env("GIT_DIR", "/elsewhere/.git") .env("ANTHROPIC_API_KEY", "key") .output() - .expect("sbx"); + .expect("insbx"); assert_eq!(String::from_utf8_lossy(&o.stdout).trim(), "[][][][key]"); } #[test] fn the_wall_limit_kills_the_whole_group() { let d = dirs(); - let tag = format!("sbx_wall_{}", std::process::id()); + let tag = format!("insbx_wall_{}", std::process::id()); let start = Instant::now(); let script = format!("(exec -a {tag} sleep 30) & (exec -a {tag} sleep 30)"); - let o = sbx(&["run", "--wall", "1", "--", "bash", "-c", &script], &d.ws); + let o = insbx(&["run", "--wall", "1", "--", "bash", "-c", &script], &d.ws); assert_eq!(o.status.code(), Some(124), "{}", text(&o)); assert!(start.elapsed() < Duration::from_secs(10)); std::thread::sleep(Duration::from_millis(300)); @@ -320,10 +320,10 @@ fn the_wall_limit_kills_the_whole_group() { } #[test] -fn killing_sbx_with_sigkill_takes_the_command_with_it() { +fn killing_insbx_with_sigkill_takes_the_command_with_it() { let d = dirs(); - let tag = format!("sbx_orphan_{}", std::process::id()); - let mut child = Command::new(SBX) + let tag = format!("insbx_orphan_{}", std::process::id()); + let mut child = Command::new(INSBX) .args([ "run", "--wall", @@ -336,7 +336,7 @@ fn killing_sbx_with_sigkill_takes_the_command_with_it() { .current_dir(&d.ws) .stdin(Stdio::null()) .spawn() - .expect("sbx"); + .expect("insbx"); let deadline = Instant::now() + Duration::from_secs(5); while !running(&tag) && Instant::now() < deadline { std::thread::sleep(Duration::from_millis(50)); @@ -349,7 +349,7 @@ fn killing_sbx_with_sigkill_takes_the_command_with_it() { while running(&tag) && Instant::now() < deadline { std::thread::sleep(Duration::from_millis(50)); } - assert!(!running(&tag), "the command outlived sbx"); + assert!(!running(&tag), "the command outlived insbx"); } #[test] @@ -359,9 +359,9 @@ fn limits_and_exit_codes() { assert_eq!(o.status.code(), Some(7)); let o = sh(&d.ws, &[], "kill -9 $$"); assert_eq!(o.status.code(), Some(137)); - let o = sbx(&["run", "--", "no-such-command-sbx"], &d.ws); + let o = insbx(&["run", "--", "no-such-command-insbx"], &d.ws); assert_eq!(o.status.code(), Some(127)); - let o = sbx(&["run", "-w", "missing-root", "--", "true"], &d.ws); + let o = insbx(&["run", "-w", "missing-root", "--", "true"], &d.ws); assert_eq!(o.status.code(), Some(125)); } diff --git a/crates/sandbox/tests/escape_windows.rs b/crates/sandbox/tests/escape_windows.rs index 2d06a3d..0b3f49d 100644 --- a/crates/sandbox/tests/escape_windows.rs +++ b/crates/sandbox/tests/escape_windows.rs @@ -1,15 +1,15 @@ //! Escape tests against the native Windows sandbox (write-restricted token, //! ACL grant, job object): the Linux escape tests that apply on Windows, -//! through the real `sbx.exe`. +//! through the real `insbx.exe`. //! //! They use only what a stock Windows (and the `windows-latest` CI runner) //! has: `cmd.exe` and Windows PowerShell. Scripts are written to files //! rather than passed inline, so no test depends on how `cmd` re-parses -//! quotes. Every run is native (`SBX_BACKEND=native`) unless the test is +//! quotes. Every run is native (`INSBX_BACKEND=native`) unless the test is //! about choosing the backend. //! //! The network tests (layer 2: the offline account and its WFP filters) run -//! only where `sbx setup-windows` has been run (CI runs it before the +//! only where `insbx setup-windows` has been run (CI runs it before the //! tests); elsewhere they print SKIPPED. They reach the network with //! `curl.exe` (in System32 since Windows 10 1803) and PowerShell. @@ -24,34 +24,34 @@ use std::time::{Duration, Instant}; use serde_json::{json, Value}; -const SBX: &str = env!("CARGO_BIN_EXE_sbx"); +const INSBX: &str = env!("CARGO_BIN_EXE_insbx"); /// Every run SID starts with this (`incord_sandbox::windows::SID_PREFIX`). const SID_MARK: &str = "4242424242"; /// The offline account (`incord_sandbox::windows::offline::ACCOUNT`). -const OFFLINE: &str = "sbx-offline"; +const OFFLINE: &str = "insbx-offline"; fn base(cwd: &Path) -> Command { - let mut c = Command::new(SBX); + let mut c = Command::new(INSBX); c.current_dir(cwd) - .env("SBX_BACKEND", "native") - .env_remove("SBX_NATIVE") + .env("INSBX_BACKEND", "native") + .env_remove("INSBX_NATIVE") .stdin(Stdio::null()); c } -fn sbx(args: &[&str], cwd: &Path) -> Output { - base(cwd).args(args).output().expect("sbx runs") +fn insbx(args: &[&str], cwd: &Path) -> Output { + base(cwd).args(args).output().expect("insbx runs") } -/// `sbx run -- cmd /d /s /c `. +/// `insbx run -- cmd /d /s /c `. fn cmd(cwd: &Path, flags: &[&str], line: &str) -> Output { let mut args = vec!["run"]; args.extend_from_slice(flags); args.extend_from_slice(&["--", "cmd", "/d", "/s", "/c", line]); - sbx(&args, cwd) + insbx(&args, cwd) } -/// `sbx run -- powershell ... -File