Repository navigation
Windows sandbox, releases and update, custom commands and plugins, .mcp.json, permission rules, /review, compaction, notifications - #13
Merged
Conversation
`sbx mcp` serves MCP over stdio. An agent can create a sandbox, write scripts and files into it, run them, read what they made, and delete it. Tools: sandbox_create, sandbox_write_file, sandbox_run (an argv `command`, or a `script` run with an `interpreter`, with stdin, cwd and timeout), sandbox_read_file, sandbox_list, sandbox_info and sandbox_destroy, each annotated readOnly/destructive. The operator sets the ceilings (--net, --allow-host, --max-wall, --policy). An agent may ask for less, never more, and a request above a ceiling is refused rather than lowered. By default a sandbox gets: - no network; - an empty environment apart from the essentials; - 4 GB of memory and 1 GB files per process; - 120 s a run (600 at most). Every run is confined to its folder (Landlock, seccomp, Seatbelt) and runs in its own process group, which is killed when the run ends, so nothing runs on in the background between calls. The file tools run in the unconfined server, so they take only relative paths without `..`, check each component for symlinks, and open with O_NOFOLLOW. A link a script planted can't lead the server out. Sandboxes are removed when the server stops (--keep to leave them). Library: Sandbox::run_captured runs with captured output (64 KB per stream kept, totals counted), optional stdin, no signal forwarding, and a group kill after the run. Tests: - tests/mcp.rs drives the real server: script, run, read, list, stdin, exit codes; escapes (writing outside, the network, host secrets, a planted symlink for read and write, `..`, absolute paths); the time limit and background cleanup; the ceilings; removal on exit, and --keep; - unit tests cover path checks, ceilings and the protocol; - live: Claude Code used the server to write and run a Python script and read its output, and its `curl` in the sandbox failed (no network). 27 unit, 15 escape and 2 MCP tests pass; clippy is clean for Linux, macOS and Windows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011DiH8n52ifWoCd5Kx2aHwT
…vsock, loader)
Ideas from openai/codex's linux-sandbox, reimplemented for a Landlock
design (bubblewrap and bind mounts are not used):
- .git/hooks and .git/config (fs.protect_git, on by default). A planted
hook, or core.fsmonitor/core.hooksPath, runs unsandboxed the next time
anyone uses git there. Landlock can't make part of a writable root
read-only without also blocking file creation in the root, so they are
snapshotted before the run, put back after, and reported: "protected
path changed by the command", and `protected_restored` from sbx mcp.
Worktrees (gitdir:, commondir) are followed. Links are recorded, never
followed, and a hooks dir swapped for a link is removed rather than
written through. Seatbelt also refuses the writes.
--no-protect-git opts out.
- Landlock ABI v6 scopes (Linux 6.12+): a command can't signal processes
outside its sandbox, or reach abstract Unix sockets made outside it.
Measured: `kill` of an outside process now gets EPERM. `doctor` reports
support.
- seccomp whenever the filesystem is confined, not only under deny/proxy:
- ioctl TIOCSTI/TIOCLINUX get EPERM (no typing into the parent's
terminal), checked on every syscall ABI;
- AF_VSOCK gets EACCES (on WSL2 vsock reaches Windows interop);
- io_uring is refused.
The socket allowlist stays under deny/proxy only.
- LD_PRELOAD, LD_AUDIT, DYLD_INSERT_LIBRARIES and DYLD_FORCE_FLAT_NAMESPACE
are removed by default (env.strip_loader_injection). RLIMIT_CORE=0 in
the child, so there are no core dumps.
Tests:
- protect: unit tests for restore, a link swap and worktrees; plus
tests/protect.rs through the real binary (a planted pre-commit hook and
core.fsmonitor are undone, ordinary work stays, opt-out keeps them);
- escape: TIOCSTI/TIOCLINUX refused on a controlling pty with
TIOCGWINSZ/termios working, and vsock refused with the network allowed;
- the Seatbelt profile orders the protected-path denies.
34 unit, 17 escape, 2 MCP and 1 protect test pass, five runs in a row.
clippy is clean for Linux, macOS and Windows.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011DiH8n52ifWoCd5Kx2aHwT
On Windows, sbx runs inside WSL2, where the Linux sandbox applies unchanged. WSL2 adds one way out: starting a Windows program (cmd.exe, powershell.exe, any .exe under /mnt/c), which runs on Windows, outside the sandbox altogether. When the filesystem is confined and WSL is detected (kernel release "microsoft"/"WSL", or a WSLInterop binfmt_misc entry), fs.block_wsl_interop (on by default) closes it: - the interop interpreter, read from the binfmt_misc entry (/init), is added to deny_read, so no .exe can start: Landlock refuses to execute a hidden interpreter, directly or for a script; - /run/WSL, where the interop sockets live, is hidden, and WSL_INTEROP is removed. Landlock can't refuse a connect to a Unix socket by path, so the socket must not be findable; - vsock was already refused by seccomp whenever the filesystem is confined. sbx doctor reports it in the filesystem line. Tests: - tests/wsl.rs checks on any Linux that a deny_read'd interpreter can't run directly or as a script's #! interpreter (with a control that it runs when not hidden); - inside WSL2 only, it tries cmd.exe, /mnt/c/.../cmd.exe, powershell.exe, WSL_INTEROP and /run/WSL, skipping elsewhere. That one has not run on a WSL2 machine yet, and the README says so; - unit tests cover WSL detection and parsing the interpreter. 36 unit, 17 escape, 2 MCP, 1 protect and 2 WSL tests pass. clippy is clean for Linux, macOS and Windows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011DiH8n52ifWoCd5Kx2aHwT
On Windows, the sandbox is the Linux one inside WSL2.
- scripts/install-windows.ps1, run once from the incode folder:
1. checks for WSL2 and a distribution (Ubuntu by default), and installs
them if missing: it asks first, elevates once with UAC, then explains
the restart and to run it again;
2. converts a WSL1 distro to WSL2 (WSL1 has no Linux kernel, so no
Landlock);
3. builds sbx inside WSL2 at ~/.local/bin/sbx, installing a C toolchain
and rustup if missing, building outside /mnt/c for speed;
4. builds sbx.exe, adds ~/.local/bin to the user PATH, and runs
`sbx doctor`.
macOS and Linux need no installer.
- sbx.exe forwards every command (run, check, doctor, mcp) into WSL2 with
wsl.exe --cd <folder>:
- path options and drive paths after `--` are translated
(C:\x -> /mnt/c/x, \\wsl$\Distro\p -> /p);
- stdio and the exit code pass through, so `sbx mcp` works for agents on
Windows;
- without WSL it refuses with the setup steps rather than running
unconfined;
- SBX_NATIVE=1 runs natively (environment and time limit only), and
SBX_WSL_DISTRO picks the distribution.
Tested here:
- path translation unit tests, which caught relative `..\x` being
refused;
- clippy is clean for windows-gnu, Linux and macOS;
- the installer parses with PowerShell 7 and refuses outside the incode
folder;
- its WSL build step, run on Linux, built and installed sbx, and
`sbx doctor` ran.
Not run on Windows: the WSL install, the elevation and the forwarding.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011DiH8n52ifWoCd5Kx2aHwT
…jects) Ported from incode's own src/sandbox/windows.rs and windows/acl.rs (left unchanged), without its incode-only dependencies. Enforced natively on Windows: - writes: the helper starts the command under a write-restricted token whose restricting SIDs are a private per-run SID, Everyone and the logon SID; the parent grants that SID one inheritable Modify ACE on each writable root and the run's private temp dir before the run, and a lease revokes it after (records in %LOCALAPPDATA%\sbx\grants; a crashed run's ACE is swept by the next). read-only grants only the temp dir. Drive roots and folders holding the profile are refused. - lifetime and limits: the command starts suspended inside a job object with KILL_ON_JOB_CLOSE; the job dies when the command ends, at the wall limit (the parent kills the helper) or when sbx dies (the helper watches it). memory_mb -> per-process committed memory, cpu_secs -> per-process user time. - environment, as everywhere; programs found on PATH/PATHEXT, never the current folder; 32-bit exit codes passed through. Not enforced natively (reported NotEnforced, refused in strict mode): network deny/proxy (no token restricts it), deny_read (restricting SIDs only gate writes), file_size_mb and open_files (no job equivalent), anywhere Everyone may write. Git Bash/msys cannot start under the token. sbx.exe picks a backend with SBX_BACKEND=native|wsl|auto (default auto; SBX_NATIVE=1 still means native): auto runs natively when native enforces the whole policy, forwards to WSL2 when it can't and WSL is set up, and otherwise refuses naming both fixes. sbx doctor reports both. sbx mcp runs natively with --net allow (scripts default to PowerShell there). Nothing here has run on Windows yet: it is checked with clippy for x86_64-pc-windows-gnu, its pure parts are unit-tested on Linux, and tests/escape_windows.rs is for the windows-latest CI runner. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011DiH8n52ifWoCd5Kx2aHwT
Built sbx.exe and the Windows tests with mingw and ran them under Wine 9: - sbx.exe doctor reports the native backend as designed; - the launch path works end to end: write-restricted token, CreateProcessAsUserW, job object, stdio and exit codes; - environment stripping, the private TEMP and the wall limit work (a busy loop was killed at 3 s, exit 124); - 46/46 unit tests pass, after fixing one: the `~` test read HOME, which Windows lacks. The code already falls back to USERPROFILE; the test now does too. Wine can't judge the rest. It enforces no Windows ACLs or restricted tokens, so writes outside the root succeed there. Its `powershell` and `icacls` are empty stubs, and it ignores the job's per-process CPU time limit. Our job limit code sets the documented values, and SetInformationJobObject accepts them. So 9 of the 15 escape_windows tests fail under Wine for those reasons and must be judged on real Windows. scripts/test-windows.ps1 runs on a Windows PC from the incode folder. It builds sbx, runs `sbx doctor`, the unit tests, escape_windows and mcp, and writes sbx-windows-report.txt to send back. It parses with PowerShell 7. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011DiH8n52ifWoCd5Kx2aHwT
- .github/workflows/release.yml: on a `v*` tag, build incode and sbx for x86_64/aarch64 Linux (gnu), x86_64/aarch64 macOS and x86_64 Windows (msvc); pack each as incode-<target>.tar.gz (.zip on Windows), publish them with a SHA256SUMS on a GitHub Release. Linux build deps match ci.yml. - scripts/install.sh (POSIX sh) and scripts/install.ps1: detect the platform, download the latest (or INCODE_VERSION) release, check it against SHA256SUMS, install to ~/.local/bin / %LOCALAPPDATA%\incode\bin (or INCODE_INSTALL_DIR), and point at PATH. - `incode update [--check]` (src/self_update.rs): compares the latest release tag with CARGO_PKG_VERSION by semver precedence, downloads this target's archive through ext_tools::fetch, refuses it unless its sha256 matches SHA256SUMS, unpacks beside the program and swaps it in by rename (Windows: current exe moved to .old first). sbx is replaced too when it sits beside incode. No new crate. - README: Install section for the prebuilt binaries and the update command. - wiring: MAX_UNWIRED ratchet lowered to 41, as the test asks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011DiH8n52ifWoCd5Kx2aHwT
- `incode review [--base <ref>] [-p]` and `/review [base]`: collect `git diff <base>...HEAD` plus uncommitted and untracked changes (base defaults to the merge-base with origin's default branch, else HEAD) and ask the model for correctness bugs, then security, then simplifications, cited as path:line, or "No issues found." (src/review.rs) - API-route compaction (src/agent/compact.rs): past 80% of the route's `context_window` (admin.json, default 200000; 0 disables) the older turns are summarised by the model into one message, keeping the last two turns and never parting a tool_use from its tool_result. `/compact [instructions]` triggers it by hand on the API route; CLI agents keep the old message. - `.github/actions/incode` composite action (comment mode answers @incode mentions and pushes changes to a new branch; review mode posts `incode review` findings), example workflow and docs/github-action.md. - INCODE_ALLOWED_TOOLS narrows the toolbox on the `-t` API route. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011DiH8n52ifWoCd5Kx2aHwT
…darwin-hyqkjj # Conflicts: # src/main.rs
…ings - notify / notify_command / notify_after_secs (admin.json): OSC 9 or bell (auto), bell, desktop (notify-send / osascript / PowerShell toast), off, when a long turn finishes or a permission/question prompt waits. Spawned and reaped on a thread; errors ignored. - statusline_command: run with the session as JSON on stdin (1.5s timeout, last good line cached); its first line replaces the facts on the input box's rule. - /cost: input/output/cache tokens per model with an estimated USD figure. One price table (PRICES in runtime/usage.rs), cache writes and reads now priced; -t prints a closing usage/cost line and the JSON result carries cost_usd (null when unpriced). - editing_mode = "vi" and /vim: a vi normal mode in the footer editor, rustyline's EditMode::Vi on the non-terminal path. - ~/.incode/keybindings.toml: flat "key" = "action" bindings for the footer editor. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011DiH8n52ifWoCd5Kx2aHwT
…darwin-hyqkjj # Conflicts: # README.md # src/cli/slash_commands.rs
Markdown files in .incode/commands/ and ~/.incode/commands/ become slash commands (frontend/test.md -> /frontend:test) with optional front matter (description, argument-hint, model, allowed-tools) and $ARGUMENTS / $1..$9 substitution. They expand into the user turn in the REPL and for incode -t "/name args", show in /help and tab completion, and never shadow a built-in (a shadowing file is reported). Plugins in ~/.incode/plugins/<name>/ or .incode/plugins/<name>/ carry a plugin.toml and bundle commands (/<plugin>:<cmd>), skills (added to the installed skills), hooks.json (added to the operator's tool hooks) and .mcp.json servers (started with the session). incode plugin list|add|remove manages them; add copies a folder or git clone --depth 1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011DiH8n52ifWoCd5Kx2aHwT
…darwin-hyqkjj # Conflicts: # README.md # src/main.rs
- Per-command allow/ask/deny rules (`Tool` / `Tool(specifier)`) from
managed.toml, ~/.incode/admin.json and .incode/settings.json (project:
deny/ask only), applied at Toolbox::run_call. deny > ask > allow > mode.
Bash lines are split on &&, ||, ;, |, &, newlines outside quotes; every
part must be allowed, any denied part denies; substitutions, sh -c, eval
and redirections are judged and never auto-allowed; wrappers (sudo, env,
timeout, ...) are looked through for deny/ask. File tools take globs with
Read/Edit families. /permissions lists the rules.
- Managed settings at /etc/incode/managed.toml (macOS, Windows paths too):
permission rules unioned and undeniable, [mcp] allow/deny applied where
every MCP server is connected. Unreadable file fails closed.
- .mcp.json and ~/.incode/mcp.json servers (stdio and Streamable HTTP via
the existing toolbox MCP client), ${VAR} / ${VAR:-default} expansion,
first-use approval for project servers keyed by name + sha256 of the
entry, and `incode mcp list|get|add|remove|approve`.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011DiH8n52ifWoCd5Kx2aHwT
…iew) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011DiH8n52ifWoCd5Kx2aHwT
…darwin-hyqkjj # Conflicts: # src/admin.rs # src/cli/mod.rs # src/main.rs # src/task_run.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Sandbox (sbx) on Windows
scripts/install-windows.ps1) andsbx.exeforwarding into WSL.scripts/test-windows.ps1produces a report from a real Windows machine; the ACL and token enforcement is only proven once that runs.Distribution
.github/workflows/release.ymlbuildsincode+sbxfor Linux, macOS and Windows on av*tag, with SHA256SUMS.scripts/install.sh,scripts/install.ps1.incode update [--check]installs the latest release only if its checksum matches.Extending incode
.incode/commands/**/*.mdand~/.incode/commands, with$ARGUMENTSand$1..$9. They also work in-t.incode plugin list|add|remove) bundle commands, skills, hooks and MCP servers..mcp.jsonand~/.incode/mcp.json(stdio and HTTP), with${VAR}expansion;incode mcp list|get|add|remove|approve.Safety
allow/ask/deny, e.g.Bash(npm test:*),Read(.env)). Compound commands are split, so every part must be allowed; deny beats ask beats allow./permissionslists them./etc/incode/managed.tomland the macOS/Windows equivalents) whose deny rules and MCP allow/deny lists can't be overridden.Review and CI
incode reviewand/reviewreview the current change.@incodeon issues and PRs, or reviews each PR./compact [instructions]compacts on demand.Terminal
statusline_commandsets a custom status line./costshows tokens and estimated USD per model, cache included./vimtoggles vi editing, and~/.incode/keybindings.tomladds key bindings.Test plan
cargo fmt --all -- --checkcargo clippy --all-targets(no warnings)cargo test --lib --bins: 2106 passedcargo test -p incord-sandbox: 78 passed (Linux)incode update --check,incode mcp add/list,incode plugin listandincode review -hby handincode update: need the firstv*taginstall.ps1andscripts/test-windows.ps1on real Windows🤖 Generated with Claude Code
https://claude.ai/code/session_011DiH8n52ifWoCd5Kx2aHwT