Skip to content
Documentation

Protect & operate

Protect the context boundary.

Control source access, command execution and supported text delivery as separate layers.

AvailableReviewed September 2026
Access boundaries and configured text filters apply to supported operations—not every host call.

LeanCTX is the Context Gateway for AI systems. It selects context, controls what reaches the model, learns how your work connects and proves what was delivered. PathJail and the command rules on this page belong to the Control step.

Inspect the effective posture

lean-ctx security status
lean-ctx doctor

These show the active local posture. Configuration can relax protections, so inspect the effective settings instead of assuming that defaults still apply.

Limit source access with PathJail

PathJail checks every file path a LeanCTX tool receives after resolving traversal (../) and symlinks. The default scope is home: from 3.11.3 everything below your home directory is readable and writable, so an agent can work across your repositories and folders without extra configuration. These zones stay closed entirely:

  • every top-level dot entry in your home directory: ~/.ssh, ~/.aws, ~/.gnupg, ~/.config, shell startup files, and other agents’ directories such as ~/.claude, ~/.codex or ~/.cursor;
  • ~/Library on macOS, ~/AppData on Windows and ~/snap on Linux, where keychains, browser profiles and mail live;
  • everything outside your home directory, such as /etc, /opt or /tmp.

Agents are told to read their own instruction files, so these open read-only on first use from 3.11.4: skills, commands, sub-agents, rules and plans under ~/.claude, ~/.codex/skills and ~/.codex/prompts, ~/.agents/skills, ~/.cursor/rules, ~/.cursor/skills and ~/.cursor/commands, ~/.gemini/commands, OpenCode’s ~/.config/opencode/agent and command, and the global CLAUDE.md, AGENTS.md and GEMINI.md. Credentials and settings beside them, such as ~/.codex/auth.json or ~/.claude/.credentials.json, stay closed, and LeanCTX tools cannot write there. A skill linked in from elsewhere below ~ is followed read-only; a link to a protected zone or outside ~ is not.

From the next release, the agents’ own settings and MCP configuration files open the same way, file by file and read-only, because agents read them to check their own setup: ~/.claude/settings.json, settings.local.json and keybindings.json, ~/.codex/config.toml and hooks.json, ~/.cursor/mcp.json and hooks.json, ~/.gemini/settings.json, ~/.codebuddy/settings.json, ~/.config/opencode/opencode.json(c) and ~/.codeium/windsurf/mcp_config.json. A token inside them is masked by the context gateway like in any other read. ~/.claude.json, credential files, sessions and transcripts stay closed.

A dot directory inside a project, such as .git or .github, is ordinary project content. A project root or allowed directory that merely contains a protected zone, such as a dotfiles repository in ~, does not open it. If $HOME is not a plausible user directory, for example / in a container, the scope falls back to the active project.

Two narrower scopes are available. projects, the default of 3.11.1 and 3.11.2, opens only folders below ~ that hold .git, Cargo.toml, package.json or another project marker, and only for reading: loose personal files such as ~/Documents/taxes.pdf stay closed, and writes stay in the session’s own project, so a manipulated agent in one repository cannot change another repository’s Git hooks. project admits only the active project.

lean-ctx allow-path /opt/src/vendor-sdk      # read and write one directory outside ~
lean-ctx allow-path ~/.config/myapp          # or open one protected location
lean-ctx allow-path --list                   # scope and extra directories
lean-ctx config set path_jail_scope projects # read other projects, write only the active one
lean-ctx config set path_jail_scope project  # only the active project

When an agent asks ctx_search, ctx_glob or ctx_tree to walk a broad directory that contains the session’s project, such as ~ or /, LeanCTX walks the project instead and says so in the result. Without a bound project the refusal tells the agent to pass the project directory.

allow-path takes effect on the next tool call; no restart is needed. It refuses /, your home directory and any directory that contains it. path_jail_scope is a global setting: a repository’s own .lean-ctx.toml cannot change it. When a path is refused, the error names the command that admits it, for you to run in your terminal. path_jail = false disables this boundary. PathJail is an application-level file boundary, not an operating-system sandbox and not a restriction on unrelated tools outside LeanCTX.

Bind each session to its own project

Every agent session binds to the project it started in: the host’s workspace roots, its project variable (CLAUDE_PROJECT_DIR and similar) or the working directory. Do not set LEAN_CTX_PROJECT_ROOT in an agent’s global MCP configuration, such as ~/.codex/config.toml. That pins one repository for every session of the agent. Setups before 3.11.1 wrote this pin themselves. Current versions remove it on the next agent refresh. lean-ctx doctor lists any pin that is left under “Project binding”, and lean-ctx doctor --fix removes it.

Give one server exactly these roots with a Workspace

From 3.11.5, a launcher that runs several projects side by side can give each MCP server exactly its own folders, and take one away while the server runs. This is opt-in: the launcher, not the agent or its client, starts the MCP server with LEAN_CTX_WORKSPACE_FILE=<absolute path>. Without that variable nothing changes.

The file names one Workspace: a primary root, further roots that are read-write or read-only, and a revision. You manage it with lean-ctx workspace:

lean-ctx workspace create --file ~/ws/app.json --id app ~/code/app
lean-ctx workspace add --file ~/ws/app.json --expect-revision 1 --read-only ~/code/shared-lib
lean-ctx workspace show --file ~/ws/app.json
lean-ctx workspace remove --file ~/ws/app.json --expect-revision 2 ~/code/shared-lib
lean-ctx workspace diagnose

create starts at revision 1 and makes the primary root read-write; it cannot be removed. add and remove (also rm) need --expect-revision with the revision you last read, so two launchers cannot overwrite each other’s change. Every command takes --json, and without --file it uses LEAN_CTX_WORKSPACE_FILE. diagnose explains what the current process is bound to and why a Workspace is refused. Inside an agent’s shell only show, diagnose and remove run, so an agent can narrow its Workspace but never widen it.

These rules keep the file trustworthy:

  • The file path is absolute and lies outside every root of the Workspace and outside LeanCTX’s own directories, so the agent cannot edit its own authority.
  • The file is a regular file with mode 0600, owned by the server’s user, and not a symlink.
  • The id has 1 to 64 characters from A-Z, a-z, 0-9, ., _ and -, and does not start with a dot.
  • A root is an existing absolute directory. /, your home directory, any directory that contains it and agent configuration directories are refused. A Workspace holds up to 64 roots besides the primary root.

While a server is bound, only the Workspace’s roots are reachable: tool paths, MCP resources, search indexes, caches, repository roots and the shell’s working directory and output capture. Client-reported roots, extra_roots, allow_paths, the home and projects scopes, ctx_multi_repo roots and path_jail = false grant nothing. Writes need a read-write root. A root you remove is gone on the server’s next tool call, without a restart. A missing, unreadable, malformed or insecurely stored file refuses every path instead of falling back to the normal scope. On Windows the file’s owner cannot be verified yet, so a configured Workspace refuses every path there for now.

lean-ctx security shows the binding in its jail line, ctx_session status names it, and the Cockpit’s scope answer carries a workspace field while the process is bound.

A Workspace bounds LeanCTX’s tools. A command run through ctx_shell is a process of its own: the Workspace sets its working directory, not what the command itself opens or writes. Use the shell allowlist and an operating-system sandbox for that, and keep the Workspace file where the agent’s user cannot write.

Gate commands independently

The shell security mode can enforce, warn or turn off command gating. Under enforcement, the command allowlist and blocked shell constructs restrict what LeanCTX executes.

lean-ctx allow --list

From 3.11.1 an agent cannot loosen LeanCTX through its own shell. LeanCTX refuses lean-ctx yolo, allow, allow-path, trust, security open, security secrets off and config set of a security, path or allowlist setting when an agent runs them through ctx_shell or a rewritten shell call. Listing, removing entries and tightening still work. Run these commands in your own terminal. Script execution through ctx_execute is not covered by the command allowlist; restrict that tool by role where it matters.

An allowlisted executable can still have powerful behavior. Review command arguments and the host’s own permissions. OS sandboxing applies only to the execution paths and platforms that actually provide it; it is not a blanket promise for every shell call.

For the reviewed script-execution sandbox path, macOS uses Seatbelt and Linux uses Landlock when the configured level and system support allow it. The Windows path does not provide the same OS sandbox: requesting that level falls back to Level 0 with a warning. PathJail and command gating remain distinct application controls; do not describe them as equivalent OS isolation. Inspect the actual execution result and host permissions on each platform.

Check what is returned

Secret detection and policy-driven content filters serve different purposes. Secret redaction has its own configuration. An active policy pack can additionally inspect supported result text for PII, classification markings and known injection patterns.

Read-time filters explains activation, actions and coverage. Detectors are not proof that a result contains no sensitive content.

Review workspace trust

Project-local configuration can request broader access or change sensitive behavior. Workspace trust gates sensitive overrides and is bound to the configuration content.

lean-ctx trust status

Review the project’s configuration before granting trust. A project you trust for code reading does not automatically deserve unrestricted shell execution.

Apply organizational controls

The Enterprise Engine binds requests to organizational or workload identity. Apply roles, project/source scope, approved providers and processing regions, budgets, approval requirements and audit retention. Revoked identity or source access must stop the affected operation rather than falling back to broader credentials.

Classify source content as untrusted evidence. A retrieved instruction, optimizer proposal or worker message cannot authorize a new model route or grant access to customer data. See governed execution.

Bind approval to the actual operation

An approval records who may perform which operation, against which source revision and policy, within a defined scope and expiry. A changed source, expired grant or revoked identity requires a new authorization decision; an old approval does not carry unrestricted permission forward.

Apply current rights when reading caches, recovering detail or continuing from a checkpoint. Enabled redaction must cover the relevant model, cache, log and recovery paths. Audit evidence records the decision and its metadata without copying sensitive matched values into the audit trail.

Match the boundary to the integration

Integration Boundary to verify
MCP Which tool calls route through LeanCTX and which result types are processed
Shell hook Which commands are intercepted versus passed through to the host
SDK Negotiated capabilities, immutable permissions and execution policy
HTTP/proxy Bind address, authentication, upstream credentials and supported protocol routes

Images and binary content have a separate return path from the MCP text-filter pipeline. Native host operations and direct model calls outside LeanCTX are not covered by that pipeline.

Engine contract & references13 references Reviewed
  • pathjail.rsrust/src/core/pathjail.rsReviewed checkout
  • workspace_authority.rsrust/src/core/workspace_authority.rsReviewed checkout
  • workspace_cmd.rsrust/src/cli/workspace_cmd.rsReviewed checkout
  • pathjail_scope.rsrust/src/core/pathjail_scope.rsReviewed checkout
  • walk_guard.rsrust/src/tools/walk_guard.rsReviewed checkout
  • allow_path_cmd.rsrust/src/cli/allow_path_cmd.rsReviewed checkout
  • project_pins.rsrust/src/hooks/project_pins.rsReviewed checkout
  • self_config.rsrust/src/core/shell_allowlist/self_config.rsReviewed checkout
  • mod.rsrust/src/core/shell_allowlist/mod.rsReviewed checkout
  • sandbox.rsrust/src/core/sandbox.rsReviewed checkout
  • secret_detection.rsrust/src/core/secret_detection.rsReviewed checkout
  • pipeline.rsrust/src/server/call_tool/pipeline.rsReviewed checkout
  • 13-security-and-governance.mddocs/reference/13-security-and-governance.mdReviewed checkout

Engine concepts describe responsibilities and behavior. Exact commands, package versions and platform contracts belong to their versioned references.

Versions & compatibility