Repository navigation
Open
Description
Problem
Kimi Code gates agent shell commands on permission prompts only — there is no enforcement layer beneath the approval UX:
- No OS sandbox. Commands approved in
manual/auto/yolomode run with full user privileges. Underkimi -p(non-interactive, defaults toauto) and AgentSwarm/goal-driven autonomous runs, nothing confines what a spawned command can read, write, or connect to — prompt injection or a model mistake becomes full-workspace/user damage. - No parsed command policy.
Bash(pattern)permission rules are glob matches over the raw command string —rm -rf a; curl …,$(…),sudo,bash -ceither bypass or false-positive, and there is no way to approve "justgit status" by command shape.dangerous-command-askexists but is AST-based only for a fixed builtin set and is skipped entirely in nonInteractive mode, so headless runs have zero command vetting. - No network egress control. A filesystem sandbox without egress control still allows read-then-exfiltrate. There is no domain allowlist, no per-connection policy, and no proxy the sandbox can route through.
Comparable agents ship all three as one containment stack (OpenAI Codex: permission profiles → Seatbelt/bwrap → execpolicy rules → MITM network proxy; Claude Code: sandbox-runtime with deny-by-default fs/network).
Proposal
Implement the three layers behind experimental flags (all default off), in agent-core-v2:
- OS sandbox (
KIMI_CODE_EXPERIMENTAL_SANDBOX):[sandbox]config withoff | read-only | workspace-write | danger-full-accessmodes; macOS Seatbelt and Linux bwrap backends; writable-root/deny-list policies with protected metadata (.git,~/.ssh); denial detection → interactive escalation, fail-closed under-p. - Exec policy (
KIMI_CODE_EXPERIMENTAL_EXEC_POLICY): layered.rulesfiles (/etc/kimi-code/rules.dmanaged →~/.kimi-code/rules.duser →.kimi-code/rules.dproject → session-runtime) withprefix_rule/network_rule, evaluated per parsed command segment (reusing the bash AST parser);forbiddenterminal,prompt→ ask interactive / deny under-p; runs in nonInteractive mode where the current dangerous-command policy does not. - Network egress (
KIMI_CODE_EXPERIMENTAL_NETWORK_EGRESS):[sandbox.network]allowlist/denylist +network_ruleenforced by a loopback HTTP CONNECT/SOCKS5 proxy; token-scoped env injection for sandboxed spawns; platform kernel rules deny direct egress where supported.
Scope
- Platforms: macOS + Linux first; Windows reports unsupported and degrades per
sandbox.allow_unsandboxed_commands. - Surface: agent-initiated
Bash/shell-command spawns; file tools keep existing permission rules. - Rollout: experimental flags → default-on per platform after soak.
A draft implementation of all three layers exists and will be linked in a PR.
Metadata
Metadata
Assignees
Labels
No labels
Activity
Ram-Pavith commentedon Oct 3, 2026
A working implementation of all three layers exists in #4115 (submitted alongside this issue) — macOS Seatbelt + Linux bwrap sandboxing behind
KIMI_CODE_EXPERIMENTAL_SANDBOX, a layered.rulesexec-policy engine (prefix_rule/network_rule, AST-based command segmentation reusing the existing bash parser, fail-closed underkimi -p), and a loopback CONNECT/SOCKS5 egress proxy enforcing[sandbox.network]allowlists — each behind its own default-off experimental flag, with tests and docs included.Happy to treat that PR purely as a reference implementation: if the direction interests the team, I'm glad to split it into smaller PRs, rework the config surface / flag names / rule DSL, or hand the design over entirely — whatever fits the roadmap.