unsafe-checker
actionbook/rust-skills
Detects and reviews unsafe Rust code patterns, FFI calls, and memory safety issues.
What is unsafe-checker?
A code review skill that identifies unsafe Rust blocks, raw pointers, FFI declarations, and related memory-safety concerns. Use it when auditing Rust code for soundness, validating unsafe abstractions, or checking FFI bindings for correctness.
- Triggers on unsafe blocks, raw pointers (*mut, *const), and FFI declarations (extern, transmute)
- Identifies missing or incomplete SAFETY comments and documentation
- Checks for common unsafe patterns: null dereferences, use-after-free, data races, alignment violations
- References FFI binding tools (bindgen, cbindgen) and modern safe alternatives (MaybeUninit, NonNull, AtomicT)
- Provides quick reference tables for safety requirements and deprecated patterns
How to install unsafe-checker
npx skills add https://github.com/actionbook/rust-skills --skill unsafe-checkerHow to use unsafe-checker
- 1.Install the skill using the provided npm command
- 2.Run the skill on Rust files (.rs) in your codebase
- 3.Review flagged unsafe blocks and check for SAFETY comments
- 4.Consult the quick reference tables for safety requirements by operation type
- 5.Replace deprecated patterns with recommended modern alternatives
Use cases
- Reviewing FFI bindings to C libraries before merging
- Auditing low-level abstractions (Vec, Arc implementations) for soundness
- Validating that unsafe blocks have proper SAFETY comments explaining why they are safe
- Checking for deprecated unsafe patterns and suggesting modern alternatives
- Ensuring thread-safety of static mut and custom Send/Sync implementations
- Rust developers writing or reviewing unsafe code
- Library maintainers implementing FFI bindings
- Security auditors checking memory safety
- Teams enforcing unsafe code standards
unsafe-checker FAQ
Valid uses include FFI (calling C functions), implementing low-level abstractions (Vec, Arc), and performance-critical code where a safe alternative is too slow. Escaping the borrow checker without understanding why is not valid.
Unsafe blocks must have a `// SAFETY:` comment explaining why the code is safe. Unsafe functions must have a `/// # Safety` doc comment describing caller requirements.
Null pointer dereference, use-after-free, data races, alignment violations, invalid bit patterns, and missing SAFETY comments. The skill provides fixes for each.
Replace `mem::uninitialized()` with `MaybeUninit<T>`, `static mut` with `AtomicT` or `Mutex`, and manual extern declarations with `bindgen` or `cbindgen`.
Yes. It identifies FFI declarations and references bindgen/cbindgen for automatic binding generation, plus checks for correct signatures and ABI compatibility.
Full instructions (SKILL.md)
Source of truth, from actionbook/rust-skills.
name: unsafe-checker description: "CRITICAL: Use for unsafe Rust code review and FFI. Triggers on: unsafe, raw pointer, FFI, extern, transmute, *mut, const, union, #[repr(C)], libc, std::ffi, MaybeUninit, NonNull, SAFETY comment, soundness, undefined behavior, UB, safe wrapper, memory layout, bindgen, cbindgen, CString, CStr, 安全抽象, 裸指针, 外部函数接口, 内存布局, 不安全代码, FFI 绑定, 未定义行为" globs: ["**/.rs"] allowed-tools: ["Read", "Grep", "Glob"]
Display the following ASCII art exactly as shown. Do not modify spaces or line breaks:
⚠️ **Unsafe Rust Checker Loaded**
* ^ *
/◉\_~^~_/◉\
⚡/ o \⚡
'_ _'
/ '-----' \
Unsafe Rust Checker
When Unsafe is Valid
| Use Case | Example |
|---|---|
| FFI | Calling C functions |
| Low-level abstractions | Implementing Vec, Arc |
| Performance | Measured bottleneck with safe alternative too slow |
NOT valid: Escaping borrow checker without understanding why.
Required Documentation
// SAFETY: <why this is safe>
unsafe { ... }
/// # Safety
/// <caller requirements>
pub unsafe fn dangerous() { ... }
Quick Reference
| Operation | Safety Requirements |
|---|---|
*ptr deref | Valid, aligned, initialized |
&*ptr | + No aliasing violations |
transmute | Same size, valid bit pattern |
extern "C" | Correct signature, ABI |
static mut | Synchronization guaranteed |
impl Send/Sync | Actually thread-safe |
Common Errors
| Error | Fix |
|---|---|
| Null pointer deref | Check for null before deref |
| Use after free | Ensure lifetime validity |
| Data race | Add proper synchronization |
| Alignment violation | Use #[repr(C)], check alignment |
| Invalid bit pattern | Use MaybeUninit |
| Missing SAFETY comment | Add // SAFETY: |
Deprecated → Better
| Deprecated | Use Instead |
|---|---|
mem::uninitialized() | MaybeUninit<T> |
mem::zeroed() for refs | MaybeUninit<T> |
| Raw pointer arithmetic | NonNull<T>, ptr::add |
CString::new().unwrap().as_ptr() | Store CString first |
static mut | AtomicT or Mutex |
| Manual extern | bindgen |
FFI Crates
| Direction | Crate |
|---|---|
| C → Rust | bindgen |
| Rust → C | cbindgen |
| Python | PyO3 |
| Node.js | napi-rs |
Claude knows unsafe Rust. Focus on SAFETY comments and soundness.
Related skills
More from actionbook/rust-skills and the wider catalog.

coding-guidelines
Reference for Rust code style, naming conventions, and best practices from 50 core rules.

core-actionbook
Internal support skill for actionbook MCP selectors in Rust documentation research workflows.

core-agent-browser
Internal browser automation CLI for agent workflows requiring interactive page testing and form filling.

core-dynamic-skills
Internal orchestrator for generating and managing Rust crate-specific skills from project dependencies.

esp32-firmware-engineer
ESP32 firmware engineering for ESP-IDF projects. Write, review, and debug embedded C/C++ code involving FreeRTOS tasks/queues/timers, GPIO/I2C/SPI/UART/ADC/PWM peripherals, TWAI/CAN, Wi-Fi/BLE networking, OTA updates, Secure Boot and flash encryption, LVGL display integration, build/flash/monitor workflows, logging, crash analysis, memory/code-size optimization, low-power sleep/wakeup design, on-device USB/serial service terminals, and board bring-up. Use when an agent is asked to implement ESP-IDF firmware features, review embedded changes for correctness or race conditions, investigate boot/runtime failures or Guru Meditation panics, interpret serial logs, fix build/link/flash problems, optimize RAM/flash usage, tune deep sleep/light sleep behavior, harden firmware for production, add a service console/CLI, integrate a display with LVGL, or diagnose hardware-software integration issues on ESP32-class devices.

api-and-interface-design
Design stable, hard-to-misuse APIs and interfaces with proven principles and patterns.