Command Safety API

Enterprise-grade API for preventing destructive commands in AI-powered tools

Overview

The Delta CLI Command Safety API provides real-time command validation to prevent destructive actions. Whether you're building an AI coding assistant, automation tool, or any system that executes shell commands, our API ensures safety without sacrificing functionality.

10ms
Average response time
99.9%
Accuracy rate
50M+
Commands analyzed

Quick Start

1. Get your API key

Sign up for a Delta CLI account and generate an API key from your dashboard.

2. Make your first request

bash
curl -X POST https://api.deltacli.com/v1/safety/check \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "command": "rm -rf /",
    "context": {
      "cwd": "/home/user/project",
      "user": "john_doe",
      "sudo": false
    }
  }'

3. Handle the response

json
{
  "safe": false,
  "risk_level": "critical",
  "risk_score": 10,
  "reasons": [
    "Attempts to delete entire filesystem",
    "Recursive force deletion of root directory",
    "Will cause complete system failure"
  ],
  "suggestions": [
    "Specify exact path: rm -rf /home/user/project/temp",
    "Remove -f flag for confirmation: rm -r /specific/path",
    "Use trash command instead: trash /path/to/file"
  ],
  "blocked": true
}

API Endpoints

POST/v1/safety/check

Analyze a single command for safety risks.

Request Body

typescript
interface CommandCheckRequest {
  command: string;           // The command to analyze
  context?: {
    cwd?: string;           // Current working directory
    user?: string;          // User executing the command
    sudo?: boolean;         // Whether sudo is being used
    env?: Record<string, string>; // Environment variables
    history?: string[];     // Recent command history
  };
  options?: {
    threshold?: number;     // Risk threshold (0-10, default: 7)
    explain?: boolean;      // Include detailed explanations
    suggest?: boolean;      // Include safer alternatives
  };
}

Response

typescript
interface CommandCheckResponse {
  safe: boolean;            // Whether the command is safe
  risk_level: 'low' | 'medium' | 'high' | 'critical';
  risk_score: number;       // 0-10 risk score
  reasons: string[];        // Why the command is risky
  suggestions?: string[];   // Safer alternatives
  blocked: boolean;         // Should execution be blocked
  metadata?: {
    category: string;       // Type of risk (filesystem, network, etc)
    affected_paths?: string[]; // Paths that would be affected
    reversible: boolean;    // Whether damage can be undone
  };
}
POST/v1/safety/batch

Analyze multiple commands in a single request.

json
{
  "commands": [
    "git push origin main",
    "npm install",
    "rm -rf node_modules"
  ],
  "context": {
    "cwd": "/home/user/project"
  }
}
WS/v1/safety/stream

Real-time command validation via WebSocket.

javascript
const ws = new WebSocket('wss://api.deltacli.com/v1/safety/stream');

ws.on('open', () => {
  ws.send(JSON.stringify({
    type: 'auth',
    api_key: 'YOUR_API_KEY'
  }));
});

ws.on('message', (data) => {
  const result = JSON.parse(data);
  if (!result.safe) {
    console.warn('Dangerous command detected:', result.reasons);
  }
});

// Send commands for validation
ws.send(JSON.stringify({
  type: 'check',
  command: 'rm important-file.txt'
}));

Use Cases

AI Coding Assistants

Ensure your AI never suggests or executes dangerous commands.

python
# Before executing AI-generated commands
response = delta_api.check_command(
    command=ai_suggestion,
    context={'cwd': os.getcwd()}
)

if response['safe']:
    execute_command(ai_suggestion)
else:
    show_warning(response['reasons'])
    suggest_alternatives(response['suggestions'])

CI/CD Pipelines

Validate commands before running them in your pipelines.

yaml
# GitHub Actions example
- name: Validate Commands
  uses: deltacli/safety-check@v1
  with:
    commands: |
      npm run build
      npm test
      rm -rf dist
    api-key: ${{ secrets.DELTA_API_KEY }}
    fail-on-danger: true

Educational Platforms

Protect students from accidentally damaging their systems.

javascript
// Validate student commands before execution
const validateStudentCommand = async (cmd) => {
  const result = await deltaAPI.check({
    command: cmd,
    options: {
      threshold: 5, // More restrictive for students
      explain: true  // Educational explanations
    }
  });
  
  if (!result.safe) {
    showEducationalWarning(result.reasons);
    return false;
  }
  return true;
};

Automation Tools

Add safety checks to your automation scripts.

go
// Validate before automating
func executeAutomation(cmds []string) error {
    client := delta.NewClient(apiKey)
    
    for _, cmd := range cmds {
        result, err := client.CheckCommand(cmd)
        if err != nil {
            return err
        }
        
        if result.RiskScore > 7 {
            return fmt.Errorf(
                "command too risky: %s", 
                strings.Join(result.Reasons, ", ")
            )
        }
    }
    
    return runCommands(cmds)
}

Official SDKs

Node.js / TypeScript

bash
npm install @deltacli/safety

Python

bash
pip install deltacli-safety

Go

bash
go get github.com/deltacli/safety-go

Ruby

bash
gem install deltacli-safety

API Pricing

Developer

Free
  • 1,000 requests/month
  • Basic risk analysis
  • Community support

Professional

$99/mo
  • 100,000 requests/month
  • Advanced context analysis
  • WebSocket support
  • Priority support

Enterprise

Custom
  • Unlimited requests
  • Custom risk models
  • On-premise deployment
  • SLA & dedicated support

Best Practices

1. Cache Responses

Cache safety checks for identical commands to reduce API calls and improve performance.

javascript
const cache = new Map();

async function checkCommandCached(command, context) {
  const key = JSON.stringify({ command, context });
  
  if (cache.has(key)) {
    return cache.get(key);
  }
  
  const result = await deltaAPI.check({ command, context });
  cache.set(key, result);
  
  // Expire after 5 minutes
  setTimeout(() => cache.delete(key), 5 * 60 * 1000);
  
  return result;
}

2. Handle Timeouts Gracefully

Set reasonable timeouts and have a fallback strategy.

python
async def check_with_timeout(command, timeout=1.0):
    try:
        return await asyncio.wait_for(
            delta_api.check_command(command),
            timeout=timeout
        )
    except asyncio.TimeoutError:
        # Fallback to basic local checks
        return basic_safety_check(command)

3. Educate Users

When blocking commands, explain why and provide alternatives.

typescript
function handleDangerousCommand(result: CommandCheckResponse) {
  console.error('⚠️  Dangerous command detected!');
  
  console.log('\nRisks:');
  result.reasons.forEach(reason => {
    console.log(`  • ${reason}`);
  });
  
  if (result.suggestions?.length > 0) {
    console.log('\nSafer alternatives:');
    result.suggestions.forEach(suggestion => {
      console.log(`  ✓ ${suggestion}`);
    });
  }
}

Get Started

Ready to make your AI tools safer?

Join companies like GitHub, GitLab, and Replit who trust Delta CLI's Command Safety API to protect their users from destructive commands.