ClawShell

repository·main·Indexed 43 days ago

https://github.com/runta-dev/clawshell

A security-privileged proxy and safety harness for OpenClaw and Hermes Agents. ClawShell secures sensitive credentials via virtual-to-real API key mapping, provides Data Loss Prevention (DLP) by scanning for PII in LLM requests and responses, and offers secure email isolation. It supports static API keys and OAuth (Device Code Flow) for services like ChatGPT and Codex. Version 0.2.1.

Tokens
20.1K
Snippets
72
Records
87
Agent score
53%

What's inside ClawShell

  1. Configure PII Safety Net (DLP) patterns

    main

    ClawShell uses configurable regex patterns in clawshell.toml to detect sensitive data (SSNs, credit cards, emails, etc.) in HTTP request and response bodies.

    For each pattern, you can specify an action:

    • block: Prevents the request from being forwarded if a match is found.
    • redact: Replaces the matched text with redacted content before forwarding.

    Note: Streaming (SSE) responses are passed through without scanning.

  2. How ClawShell works as a security proxy

    main

    ClawShell acts as a security-privileged sidecar process between an LLM Agent (like OpenClaw or Hermes Agent) and upstream LLM providers (OpenAI, Anthropic, OpenRouter).

    The Security Model:

    • Key Isolation: The Agent only holds virtual keys. The real API keys are stored in a privileged directory (/etc/clawshell) and are only readable by the clawshell system user. ClawShell performs the mapping from virtual to real keys during request forwarding.
    • DLP (Data Loss Prevention): ClawShell scans request and response bodies for PII using regex patterns. It can either block the request or redact the sensitive text.
    • Email Isolation: When providing email access, ClawShell uses sender-based filtering so that a virtual key only sees mailbox content allowed by specific sender rules.
    • Authentication: Supports both static API keys and OAuth (via Device Code Flow) for services like ChatGPT/Codex.
  3. Use OAuth Authentication (Codex / ChatGPT)

    main

    ClawShell supports OAuth-based authentication as an alternative to static API keys, specifically for services like ChatGPT/Codex.

    • Device Code Flow: The clawshell onboard wizard prints a URL and a code. You authorize the connection from any device by visiting the URL and entering the code; no browser is required on the server.
    • Automatic Refresh: Access tokens are refreshed automatically before expiration.
    • Request Translation: When using Codex OAuth, ClawShell automatically translates OpenAI Chat Completions API requests into the ChatGPT Responses API format.
  4. Integrate with OpenClaw

    main

    When selecting OpenClaw during sudo clawshell onboard, ClawShell:

    1. Backs up ~/.openclaw/openclaw.json to .bak files (mode 000).
    2. Patches OpenClaw configuration using openclaw config set to route requests through ClawShell.
    3. Writes a get-email-messages skill bundle to <openclaw_root>/skills/ if email integration is enabled.
    4. Optionally runs openclaw models set clawshell and openclaw gateway restart to finalize the setup.
  5. Configure OAuth Authentication (Codex / ChatGPT)

    main

    Instead of static API keys, you can use OAuth for ChatGPT/Codex accounts.

    Setup via Onboarding

    During sudo clawshell onboard, select "Codex / ChatGPT (OAuth)" as the provider. A device code flow will start:

    1. A URL and one-time code will be printed to the terminal.
    2. Open the URL on any device and enter the code.
    3. Tokens are automatically saved to /etc/clawshell/oauth/.

    Manual Configuration

    In clawshell.toml, define a key with auth = "oauth" and specify the oauth_provider. You must also define the provider in the [[oauth_providers]] section.

    When using Codex OAuth, requests to /v1/chat/completions are automatically translated to the ChatGPT Responses API format and routed to chatgpt.com/backend-api/codex.

    # OAuth-backed key
    [[keys]]
    virtual_key = "vk-codex-001"
    auth = "oauth"
    oauth_provider = "codex"
    provider = "openai"
    
    # OAuth provider definition
    [[oauth_providers]]
    provider = "codex"
  6. Onboard ClawShell via the interactive wizard

    main

    The onboard command is an interactive setup wizard that must be run with sudo. It performs the following tasks:

    1. Agent Selection: You must choose exactly one downstream agent to wire through ClawShell: OpenClaw or Hermes Agent.
    2. System Setup: Creates the clawshell system user and secures /etc/clawshell (mode 700) and /var/log/clawshell.
    3. Configuration: Walks you through provider selection, API key entry, and virtual key generation, writing the final config to /etc/clawshell/clawshell.toml.
    4. Agent Integration: Automatically patches the chosen agent (OpenClaw or Hermes) to route through ClawShell.
    5. Daemon: Starts the ClawShell daemon.

    Note: You can only configure one agent per run. To switch agents, you must re-run the onboard command.

    sudo clawshell onboard
  7. Integrate with Hermes Agent

    main

    ClawShell can act as a custom provider for the Hermes Agent.

    Automatic Integration

    When selecting Hermes Agent during sudo clawshell onboard, ClawShell:

    1. Writes a get-email-messages skill bundle to ~/.hermes/skills/ (owned by your user).
    2. Configures Hermes via hermes config set with:
      • model.provider = "custom"
      • model.base_url = "http://<server_host>:<server_port>/v1"
      • model.default = <chosen_model_id>
      • model.api_key = <your_clawshell_virtual_key>

    Manual Integration

    If you prefer to configure Hermes manually (run as your normal user, not root):

    hermes config set model.provider custom
    hermes config set model.base_url http://127.0.0.1:18790/v1
    hermes config set model.default <your-model-id>
    hermes config set model.api_key <your-clawshell-virtual-key>

    To detach Hermes from ClawShell, set the provider back to auto-detect:

    hermes config set model.provider auto
  8. Install ClawShell

    main

    You can install ClawShell using Cargo, NPM, or by building from source. After installation, you must run the onboard wizard with elevated privileges to set up the security boundary (e.g., creating /etc/clawshell and setting file permissions).

    Cargo

    cargo install clawshell --locked
    sudo clawshell onboard

    NPM

    npm install -g @clawshell/clawshell
    sudo clawshell onboard

    Build from Source

    RUSTFLAGS="--remap-path-prefix=$(pwd)=. --remap-path-prefix=$HOME=/" cargo build --release
    cargo install clawshell --locked
    sudo clawshell onboard
  9. Configure the onboarding target

    main

    When running the ClawShell onboarding wizard, you must specify which downstream LLM client to route through the ClawShell proxy. You can choose between two targets:

    1. Openclaw: Patches the OpenClaw configuration file (typically located at ~/.openclaw/openclaw.json).
    2. Hermes: Configures the Hermes Agent using the hermes config set command.

    Note that you can only select exactly one target per onboarding run.

    use std::path::PathBuf;
    
    // Example of selecting the Openclaw target
    let target = OnboardTarget::Openclaw {
        config_path: PathBuf::from("~/.openclaw/openclaw.json"),
    };
    
    // Example of selecting the Hermes target
    let target = OnboardTarget::Hermes;
  10. How DLP actions (Block vs Redact) work

    main

    The DlpScanner uses two primary actions defined in DlpAction to handle sensitive data:

    1. Block: These patterns are used to identify high-severity violations. When using scan_and_redact, matching Block patterns are reported in the blocked field of the ScanResult but are not replaced in the redacted output.
    2. Redact: These patterns are used for PII masking. When using scan_and_redact, matching Redact patterns are replaced in the output with the string [REDACTED:<name>].

    Note on redact_all: When calling redact_all, the distinction between Block and Redact is ignored; all matching patterns are replaced with the redaction string.

  11. Configure ClawShell server network settings

    main

    By default, ClawShell listens on 127.0.0.1:18790. You can override the bind address and port at runtime using environment variables:

    • CLAWSHELL_SERVER_HOST: The host address to bind to.
    • CLAWSHELL_SERVER_PORT: The port to listen on.
    CLAWSHELL_SERVER_HOST=0.0.0.0 CLAWSHELL_SERVER_PORT=17890 clawshell start --foreground
  12. Select an authentication method during onboarding

    main

    ClawShell supports two authentication methods during the onboarding process:

    • StaticKey (Default): Uses a traditional static API key. When using this method, you must provide a real_api_key which ClawShell will then wrap into a virtual_api_key.
    • OAuth: Uses an OAuth provider (e.g., "codex") to supply access tokens at runtime. When using this method, the real_api_key field is left empty.
    use std::path::PathBuf;
    
    // Using a static API key
    let auth = OnboardAuthMethod::StaticKey;
    
    // Using an OAuth provider
    let auth = OnboardAuthMethod::OAuth {
        provider_id: "codex".to_string(),
    };