# apexe: Run Your Tools. Enforce Your Rules.


Your team already has tools that work: command-line utilities, internal CLIs, operational scripts, and HTTP APIs. They encode years of decisions about how your systems should behave.

As AI agents begin using those tools, a new set of questions becomes practical. Which operations may an agent call? Which arguments change the risk? What happens when a command touches a sensitive path? What record explains why a call was permitted or refused?

We built **apexe** to put those questions on the execution path.

apexe provides governed execution for existing CLI tools and HTTP APIs. Humans and agents can run CLI commands locally, while protocol clients can access CLI modules and imported OpenAPI operations through MCP or A2A. The shared layer brings together typed inputs, configured access rules, approval checks, and audit records.

**Run your tools. Enforce your rules.**

## Start with the tools you already operate

Adopting apexe starts outside the tool's source code.

Its deterministic scanner reads CLI help, man pages, and shell completions. It turns discovered flags and arguments into JSON Schema and reusable YAML bindings. Scanning requires no LLM and no changes to the CLI's source code.

That makes an existing command a candidate for a structured interface. A consumer can inspect its declared inputs; an operator can review its annotations and policy; the executor can validate a request before starting a subprocess.

Discovery also has to respect the machine it runs on. A command named `ls` may be BSD, GNU, or another implementation. apexe detects variants and applies matching reviewed overlays from an external rules corpus, normally [cli-permissions](https://github.com/aiperceivable/cli-permissions). Those overlays supply curated command facts that automated discovery can miss.

The result is a contract tied to the installed tool and applicable rules. Coverage still depends on what the tool exposes and what has been reviewed.

## Coverage has three speeds, and one of them is explicit

Local execution is a first-class entry point. A developer or terminal-capable agent can use explicit `exec` without starting an MCP server or activating shell integration.

Begin by preparing command coverage:

```bash
apexe init
apexe list --verbose
```

Initialization obtains the configured rules, checks matching installed tools, and prepares bindings plus a starter ACL. Review that policy before execution. For a newly generated policy, local readonly operations receive allow rules, while destructive, network-reaching, and unknown modules default to deny. Existing manual rules and policy defaults are preserved.

What a binding can then do depends on how well its grammar is known. That trust is recorded per route, not per tool:

| Route state | What it means | How it runs |
| --- | --- | --- |
| **Reviewed** | Every flag the route can emit, including tool-level globals, came from a curated overlay | Native argv, or a PATH shim |
| **Scanned** | The route has a binding, but its grammar was inferred | Opt-in only, via `apexe env --enable --scanned readonly\|all` |
| **Module JSON** | No native grammar, but the module surface is advertised | Explicit JSON input to `apexe exec` when its normal checks permit |

Native execution is the default for reviewed routes. Inspect a preflight first:

```bash
apexe exec --dry-run -- ls -la
```

Read the result. If the call is admitted under the intended policy, submit execution separately:

```bash
apexe exec -- ls -la
```

Native execution preserves the child's stdout, stderr, and exit status. The current reviewed pilot covers **BSD `cat`, `head`, and `ls`** — a small surface, deliberately. GNU scanning support alone does not establish native eligibility, and `apexe exec` admits reviewed routes only.

The scanned tier exists for the gap between those two. A scanned route parses and validates the caller's argv against the scanned schema, then executes the **original argv**; it never rebuilds or reorders the command line. Schema inference is not a reviewed contract, so path-guard coverage for arguments the scanner did not type may be incomplete — `readonly` admits only readonly, non-destructive, closed-world modules, and `all` is for bindings you have actually reviewed. Every scanned execution is audited with `tier: scanned`.

Per-route trust also means a partially reviewed tool stays usable. A `mode: merge` overlay that fully covers one route makes that route reviewed while its siblings remain scanned-only — `apexe sh --check` lists them among the excluded bindings with the reason, and `apexe list --diagnostics` shows any route an overlay dropped outright.

One caution about overlay authoring: a tool with subcommands can declare the routes it opens with `commands[]` and `global_flags` at `schema_version: "2.0"`. That spelling is a preview this build accepts ahead of the published schema, which still pins `1.0`/`1.1` and rejects both fields. Use 2.0 files for local experiments, not as a portable format. Routes an overlay does not declare are dropped and reported as scan inventory: declaring is permitting, not describing.

## Make the route compulsory in your agent host

A Skill is a document. It tells an agent to route commands through `apexe exec`, and it works well — but it is advice, and advice is not a boundary. What actually decides whether a command reaches apexe is the agent host's execution interface.

apexe supports that interface directly, rather than leaving it as an exercise for the reader.

Install the shims, the activation helpers, and the stable launcher in one step:

```bash
apexe env --enable
source ~/.apexe/bin/apexe-activate.sh
apexe sh --check
```

`apexe-sh` is installed next to the shims. It prepares `PATH` and the apexe environment, then replaces itself with your real shell through `exec`. It does not parse the command string, proxy output, or stay in the process tree, so builtins, pipelines, and redirections keep their normal semantics.

`apexe sh --check` is the readiness report you want before trusting any of this. It covers the real shell, the entry point, the shim manifest, ACL state, the local environment policy, the loader-variable denylist, verified and scanned routes, bindings that were excluded from shims with the reason, and the host snippets for OpenCode, pi, Codex, and Claude Code. Add `--format json` to diff it in CI.

Then wire the host you actually use:

```bash
apexe agent opencode          # print the configuration and the apexe-sh path
apexe agent --check opencode  # verify launcher and host readiness, no writes
apexe agent opencode --write  # merge into opencode.json atomically
```

The same command speaks `pi`, `codex`, and `claude`. `--scope project|user` selects the file to write, and `--mcp-only` produces a deployment that starts no shell at all. Two details are worth knowing before you rely on `--write`: it merges into existing JSON and refuses a file that is not valid JSON, and for OpenCode and pi it refuses when `apexe-sh` is not installed — those hosts start every command through that path, so a missing launcher does not fall back to the system shell, it stops the host from running anything.

The four hosts are not the same integration:

| Host | Integration | Notes |
| --- | --- | --- |
| OpenCode | `shell` → absolute `apexe-sh` path | Its shell tool invokes `apexe-sh -c "<command>"` |
| pi | `shellPath` → `apexe-sh` | Exports `APEXE_SHELL_DEPTH=1` to nested shells |
| Codex | Login-shell `PATH` activation | Does not accept `apexe-sh` as its shell; zsh activation now covers `.zprofile`, so noninteractive login shells resolve shims |
| Claude Code | `PreToolUse` hook, or `PATH` at launch | Rejects `apexe-sh` as `SHELL`/`CLAUDE_CODE_SHELL`; a simple external command is rewritten to `apexe sh -c '<command>'` |

For Claude Code, the hook is one command:

```bash
apexe hook claude
```

It rewrites simple external commands through `updatedInput` and leaves builtins, pipelines, redirections, and compound commands alone — a one-shot `apexe sh -c` would not preserve their semantics, so those keep relying on the installed PATH shims. An `--persistent` mode routes every Bash call through a detached governed session that keeps `cd`, variables, functions, and aliases across calls; it is experimental, with an idle timeout and an explicit stop.

Prefer the hook or the shell path over the Skill. Keep the [shared Agent Skill](https://github.com/aiperceivable/apexe/blob/main/docs/agent-skill.md) for hosts that cannot be configured either way — it remains the fallback, not the enforcement mechanism.

## Choose the interface that fits the consumer

The same project can support several ways of using its tools:

| Consumer | apexe entry point |
| --- | --- |
| Developer or terminal-capable agent | Local `exec`, with native argv or module JSON |
| Agent host that selects a shell | `apexe-sh`, configured by `apexe agent` |
| Agent host with a pre-tool hook | `apexe hook claude` |
| Existing shell workflow | Optional `env` PATH shims for eligible external commands |
| Host that cannot be configured | Agent Skill plus explicit `apexe exec` |
| MCP client | `serve` with CLI modules and optional OpenAPI imports |
| A2A client | `a2a` with the same module sources |

For shell workflows, install and activate eligible PATH shims after reviewing bindings and policy:

```bash
apexe env --enable
apexe env --check
```

The shims let supported external commands keep their familiar names while entering the local governance path. Eligibility remains explicit; builtins, aliases, absolute paths, and uncovered commands can bypass PATH shims.

For an MCP client, start with your reviewed ACL:

```bash
apexe serve --acl ~/.apexe/acl.yaml
```

For A2A:

```bash
apexe a2a --acl ~/.apexe/acl.yaml
```

Servers require an explicit `--acl` for access control. Local execution uses caller `local` and loads the default ACL when present; without a loaded ACL, access control is inactive. Transport authentication and operation authorization are separate configuration concerns.

## Include existing HTTP APIs

apexe can also import operations from an OpenAPI 3.0 or 3.1 JSON/YAML document at MCP or A2A server startup. These operations sit alongside CLI modules and share schema validation, configured ACLs, filters, and auditing.

For your own specification, API origin, and reviewed policy:

```bash
apexe serve --openapi ./openapi.yaml \
  --openapi-base-url https://api.example.com \
  --acl ./acl.yaml --no-log-arguments
```

The initial proxy surface supports path parameters, query parameters for GET/DELETE/HEAD/OPTIONS/TRACE, JSON bodies for POST/PUT/PATCH, and JSON responses. Multipart uploads, per-input header/cookie parameters, and non-JSON responses are outside that surface. Specification-fetch credentials, upstream API credentials, and incoming client credentials stay separate.

This is a server feature. Local `exec`, PATH shims, and `apexe-sh` execute CLI commands. Remote APIs retain responsibility for their own data authorization. The [OpenAPI guide](https://github.com/aiperceivable/apexe/blob/main/docs/openapi.md) includes a runnable example using a temporary local API.

## Give execution decisions a concrete basis

Several controls work together on governed CLI calls:

- **Schema validation** checks declared input types and constraints.
- **Configured ACLs** determine which callers may invoke which modules.
- **Approval checks** account for the arguments actually sent when a requirement comes from escalating flags. Native local execution, PATH shims, and `apexe sh` prompt on the controlling terminal and refuse a non-interactive call with a remedy rather than hanging. MCP interactive approval is opt-in and requires a compatible client. A2A has no interactive approval transport; approval-store support requires library integration.
- **Path checks** resolve schema-typed filesystem arguments against system and credential boundaries.
- **Process controls** use argv without evaluating a shell command string, and enforce timeouts. Captured output is bounded.
- **Environment policy** follows the entry point. Captured execution — MCP, A2A, and module JSON — clears the environment and passes a small allowlist, so secrets in apexe's environment cannot leak to a wrapped tool. Local `exec`, PATH shims, and `apexe sh` inherit the caller's environment so credential helpers that read `GH_TOKEN`, `AWS_PROFILE`, `KUBECONFIG`, or `SSH_AUTH_SOCK` keep working, while dynamic-loader variables (`LD_PRELOAD`, `LD_LIBRARY_PATH`, `DYLD_*`) are removed before the child starts. That inheritance is a trust decision, not a gap: a locally executed tool can use your credentials.
- **Audit records** capture executions, refusals, and ACL decisions without storing argument values in the audit trail, and mark the execution tier that was used.

These controls have a defined reach. apexe is **not an OS sandbox**: an allowed process runs with the host process's privileges. The calling shell owns pipes and redirections, and schema-based path checks cover declared path arguments rather than every file a process could access. The launcher changes command lookup order — `apexe sh --locked` narrows `PATH` to the shim directory plus explicit `--allow-path` entries, but absolute paths, builtins, functions, and `sudo` still run outside it. The scanned tier validates argv without turning inferred grammar into a reviewed contract. Deploy apexe within the account, container, VM, or OS isolation boundary your workload needs; the [threat model](https://github.com/aiperceivable/apexe/blob/main/docs/threat-model.md) explains that boundary.

## Keep the contract useful as tools change

A CLI upgrade can change the interface an agent relies on. `apexe verify` compares fresh help, man-page, and completion information against the recorded pre-overlay source baseline without replacing the bindings.

```bash
apexe verify --report ./drift-report.json
```

Optional explicit behavioral cases test concrete invocations. Recorded evidence is tied to binding, binary, and case digests; changed or missing inputs invalidate earned confidence. That evidence is scoped to the cases tested. The [verification guide](https://github.com/aiperceivable/apexe/blob/main/docs/verification.md) covers admission rules and the separate OS isolation used for those cases.

Coverage is worth auditing too, because a narrowed overlay is a way to lose a route quietly:

```bash
apexe list --diagnostics
```

That report lists the routes each overlay left out of the declared surface — not executable, not advertised, and not restorable by widening the scanned policy — and, when a policy is loaded, the ACL grants that match no module on disk. Those grants are usually a merge artefact: the operator reads a permission in `acl.yaml` that nothing can exercise.

## Try one workflow you can inspect

Pick a trusted installed CLI and a small task. Initialize coverage, review its binding and policy, inspect a preflight, and examine the resulting audit record. Then make it unavoidable for one agent host and run the same task from inside that agent.

apexe is written in Rust and licensed under Apache-2.0. Start with the [repository](https://github.com/aiperceivable/apexe), choose a [prebuilt binary](https://github.com/aiperceivable/apexe/releases) or source installation, and follow the [quick start](https://github.com/aiperceivable/apexe/blob/main/docs/quickstart.md) and the [shell integration guide](https://github.com/aiperceivable/apexe/blob/main/docs/agent-shell.md).

We would like to hear which CLI or API you want to bring into a governed agent workflow—and which execution decision you need to be able to explain.

