Alcoholless: 适用于 Homebrew、AI 代理等的 macOS 上的轻量级安全沙箱
[Homebrew] [✦Gemini] [֎Codex] [✴️Claude Code] [OpenCode]
Alcoholless is a lightweight security sandbox, primarily for macOS programs.
While Alcoholless was originally made for the sake of securing Homebrew, basically it can be used for almost any CLI programs. Notably, Alcoholless is useful for allowing an AI agent to run shell commands with less risk of breaking the host operating system.
See also my blog article:
Alcoholless Homebrew (alcless brew) executes Homebrew in a separate environment
so as to reduce concerns around potential supply chain attacks.
cd ~/SOME_DIRECTORY
alcless brew install xz
alcless xz SOME_FILEIn the example above, xz works as a separate user with an access for the copy of the current directory.
The changed files are synced back to the current directory when the command exits, with a confirmation screen (see below).
Other directories are inaccessible, as long as the permissions are set correctly.
Confirmation screen
…[!IMPORTANT]
Alcoholless uses a Tier 3 configuration of Homebrew that uses a custom installation prefix. Some formulae may not work.
Alcoholless is useful for sandboxing AI coding agents too. The file changes made by the AI are committed to the host filesystem only after the user confirmation.
cd ~/SOME_DIRECTORY
alcless brew install gemini-cli
alcless geminicd ~/SOME_DIRECTORY
alcless brew install codex
alcless codexcd ~/SOME_DIRECTORY
alcless brew install claude-code
alcless claudeTroubleshooting
Claude Code may need extra steps for the initial setup (issue #52):
alcless_USER_default via the Fast User Switching icon in the macOS menubar.alcless_USER_default desktop:brew install claude-code
claudeclaude.alcless_USER_default desktop.cd ~/SOME_DIRECTORY
alcless zsh -c "security unlock-keychain && claude"[!TIP]
AI coding agents typically prints the authentication URL on the first run. Make sure to copy and paste the URL in a single line. (Hint: use TextEdit to eliminate extra line delimiters)
cd ~/SOME_DIRECTORY
# Specify --force-bottle to avoid recompilation
alcless brew install --force-bottle opencode
alcless opencodeOllama integration
To use a local model such as Gemma or Qwen, launch OpenCode via Ollama:
cd ~/SOME_DIRECTORY
alcless brew install --force-bottle opencode ollama
alcless ollamaSelect Launch OpenCode, press →, and choose a model such as gemma4.
Requirements:
To install Alcoholless, run:
make
sudo make installMakefile variables:
PREFIX: installation prefix (default: /usr/local)To initialize the "default" sandbox (user account alcless_${USER}_default):
alclessctl create defaultTo run a command:
alclessctl shell default -- brew install xzor
alcless brew install xzTo run a command, without rsyncing the current directory:
alclessctl shell --plain default bashor
alcless --plain bashTo remove the sandbox:
alclessctl delete defaultTo remove the sandbox, while keeping the home directory of the sandbox user (/Users/alcless_${USER}_default):
alclessctl delete --keep-home defaultThe command line is designed to be similar to limactl.
Just plain old utilities under the hood: sudo, su, pam_launchd, and rsync.
A future version may also incorporate FSKit to replace rsync.
Alcoholless creates /etc/sudoers.d/alcless_exampleuser_default for the user exampleuser, with the following content:
exampleuser ALL=(root) NOPASSWD: /usr/bin/su - alcless_exampleuser_default -c *This sudo configuration allows exampleuser to run /usr/bin/su - alcless_exampleuser_default -c * as the root user,
without the password.
The su command being executed through sudo can run an arbitrary command as the sandbox user alcless_exampleuser_default.
See FAQs for the reason why su is wrapped inside sudo.
su inside sudo?Because sudo doesn't isolate "a specific Mach bootstrap subset, audit session and other characteristics not recognized by POSIX" (see launchd(8)) on macOS,
while su isolates them.
e.g., sudo -u alcless_exampleuser_default open -a TextEdit opens the TextEdit application as the current user, not as alcless_exampleuser_default.
This issue could be solved by copying the pam_launchd.so configuration from /etc/pam.d/su to /etc/pam.d/sudo,
however, touching such system configuration files might be scary.
So, the current workaround is to just wrap su inside sudo.
Because containers are not supported on macOS.
Because VM has several disadvantages:
The alclessctl CLI is designed to mimic the limactl CLI for an easier learning,
however, Alcoholless does not use Lima under the hood.
暂无开放 Issues,或尚未同步最近议题。