sudo_ai

Crates.iosudo_ai
lib.rssudo_ai
version
sourcesrc
created_at2025-05-07 19:41:16.458162+00
updated_at2025-05-07 19:41:16.458162+00
description'Rewrite' of sudo with AI
homepagehttps://github.com/CestDiego/sudo-ai
repositoryhttps://github.com/CestDiego/sudo-ai
max_upload_size
id1664373
Cargo.toml error:TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Berr (CestDiego)

documentation

README

sudo_ai

crates.io License: MIT

A command-line tool that uses AI to give you advice before you run a command with sudo.

Overview

sudo_ai acts as a wrapper around sudo. When you try to execute a command using sudo_ai, it first sends the command to an OpenAI model to get advice on whether the command is safe or appropriate to run with sudo privileges. It then presents this advice to you. If the AI advises to "ALLOW", you'll be prompted for final confirmation before the command is executed.

This tool aims to provide an extra layer of scrutiny for sudo commands, helping to prevent accidental or potentially harmful operations.

Features

  • AI-Powered Advice: Leverages OpenAI models to analyze sudo commands.
  • Streaming Response: AI advice is streamed to your terminal for a more responsive experience.
  • User Confirmation: Even with AI approval, you have the final say before execution.
  • Configurable:
    • Set your OpenAI API key.
    • Choose the OpenAI model (defaults to o4-mini).
    • Specify a custom OpenAI API base URL if needed.
  • Security Conscious: Designed to give advice; the final decision and responsibility to run the command remain with the user.

Installation

Once sudo_ai is published on crates.io, you can install it using cargo:

cargo install sudo_ai

Ensure that $HOME/.cargo/bin is in your system's PATH.

Usage

Simply prefix the command you intend to run with sudo with sudo_ai instead.

sudo_ai <your_command_and_arguments>

Example:

sudo_ai apt update && sudo_ai apt upgrade
# or
sudo_ai rm -rf /some/critical/path

How it works:

  1. You run sudo_ai your_command.
  2. sudo_ai sends your_command to the configured OpenAI model, asking if it should be allowed with sudo privileges.
  3. The AI's advice (including reasoning and a final "ALLOW" or "DENY") is streamed to your console.
  4. If the AI's final decision is "ALLOW", sudo_ai will ask for your confirmation (yes/no).
  5. If you confirm, sudo_ai then executes the original command using the actual sudo.
  6. If the AI's decision is not "ALLOW", or if you decline confirmation, the command is not executed.

Configuration

sudo_ai is configured using environment variables:

  • OPENAI_API_KEY (Required): Your OpenAI API key. The program will not run without this key.

    export OPENAI_API_KEY="sk-your_openai_api_key"
    
  • OPENAI_MODEL (Optional): The OpenAI model to use for advice. Defaults to o4-mini.

    export OPENAI_MODEL="gpt-4-turbo"
    
  • OPENAI_BASE_URL (Optional): The base URL for the OpenAI API. Defaults to https://api.openai.com/v1. Useful if you are using a proxy or a compatible API endpoint. (Gemini, Claude, etc)

    export OPENAI_BASE_URL="https://your-proxy-url/v1"
    

You can set these in your shell's configuration file (e.g., .bashrc, .zshrc) for them to persist across sessions.

License

This project is licensed under the MIT License - see the LICENSE file for details (though you'll need to create this file or refer to the one in Cargo.toml).

Disclaimer

This is a J-O-K-E. Think leftpad in npm. But it does work.

sudo_ai provides advice generated by an AI model. This advice is for informational purposes only and should not be the sole basis for decisions with security implications. Always use your own judgment and understand the commands you are running with sudo. The developers of sudo_ai are not responsible for any misuse or damage caused by commands run through this tool.


Commit count: 0

cargo fmt