Skip to content

CodeGuard

CodeGuard detects code snippets, script tags, SQL statements, and shell commands in LLM input/output to prevent code injection or unwanted code execution.

Overview

Property Value
Latency <5ms
Memory 80 KB
Async No
ML Required No
License Community

Categories

Category Examples
Python def, import, class, print()
JavaScript function, const, var, =>
Sql SELECT, INSERT, UPDATE, DELETE, DROP
Shell sudo, chmod, rm, curl, wget
Html <script>, <iframe>, onclick=
Rust fn, let mut, impl, pub struct
Generic Fenced code blocks (```)

Usage

Rust

use oxideshield_guard::guards::CodeGuard;
use oxideshield_guard::{Guard, GuardAction};

let guard = CodeGuard::new("code_block")
    .with_action(GuardAction::Block);

let result = guard.check("Run this: `rm -rf /`");
assert!(!result.passed);

Python

from oxideshield import code_guard

guard = code_guard(action="block", allow_fenced=False)
result = guard.check("Run this: `rm -rf /`")
assert not result.passed

Configuration

guards:
  - type: code
    action: block
    allow_fenced: false
    categories:
      - shell
      - sql
      - html

Research References