Skip to main content

Overview

Andi AIRun scripts are executable markdown files that can read code, run commands, write files, and automate complex workflows. Scripts use a shebang to specify the AI model and permissions, then contain natural language instructions that the AI executes.

Basic Script Structure

A minimal script looks like this:
Make it executable and run it:

The -S Flag (Essential for Shebangs)

Standard env only passes a single argument. To pass flags to ai in a shebang, you need env -S (split string):
-S tells env to split the string into separate arguments. Use it whenever your shebang has flags.

Permission Modes

By default, scripts run with limited permissions — they can read code but won’t write files or run commands without approval. For scripts that need to take actions, set a permission mode.

Available Modes

--bypass and --skip both result in no permission prompts, but --skip is more aggressive — it overrides any --permission-mode flag. Use --bypass when you may want to compose with other permission settings in the future.

Examples

Read-only script (no permission flags needed):
Full automation (script needs to run commands and write files):
Or equivalently: #!/usr/bin/env -S ai --bypass Granular permissions (only allow specific tools):

Common Patterns

Run Tests and Report Results

Generate Documentation

Pipe Data In, Get Results Out

Read-only analysis of piped input doesn’t need permission flags.

Code Review with Provider Selection

Composable Script Chains

Chain scripts together like Unix programs:
Important: Child scripts in pipelines should be simple prompt mode (without --cc). Only the top-level dispatcher should have tool access.

Security Warnings

--skip, --bypass, --permission-mode bypassPermissions, and --dangerously-skip-permissions all give the AI full access to your system. Use them carefully:
  • Only run trusted scripts in trusted directories
  • Prefer --allowedTools for granular control when full access isn’t needed
  • In CI/CD, run inside containers or sandboxed environments
  • Never pipe untrusted remote scripts with bypass permissions:

Quick Reference

| I want to… | Shebang | |--------------|---------|| | Analyze code (read-only) | #!/usr/bin/env ai | | Use a specific provider | #!/usr/bin/env -S ai --aws | | Run commands and write files | #!/usr/bin/env -S ai --skip | | Restrict to specific tools | #!/usr/bin/env -S ai --allowedTools 'Bash(npm test)' 'Read' | | Full automation with provider | #!/usr/bin/env -S ai --aws --opus --skip |

Next Steps

Script Variables

Use YAML front-matter to make scripts reusable with CLI overrides

Live Output

Stream progress in real-time for long-running scripts

Permissions

Deep dive into permission modes and security best practices

CI/CD Automation

Run scripts in CI/CD pipelines with proper error handling