#!/bin/bash # configure reads TITLE and DESCRIPTION # shellcheck disable=SC2034 TITLE="Agent sandbox" # shellcheck disable=SC2034 DESCRIPTION="Choose what agents may read, e.g. iCloud Drive" # Your own sandbox config, which every sandboxed agent reads after # sandbox/config/base.json (see sandbox/agent) SANDBOX_CONF="$CONF_DIR/sandbox/base.json" source "$CONNECTOR/configure.d/lib/json.sh" source "$CONNECTOR/configure.d/lib/agents.sh" # Folders the sandbox hides from agents (sandbox/config/base.json) that you # may let them read: "path|what it is". Your SSH keys, keychains, password # managers, browsers, mail and messages aren't here; they're always hidden. # A path in allowRead can be read even inside one in denyRead, so letting # agents read one is adding it to allowRead in your own config. # Cloud drives are hidden because they hold everything you've put in them, # and reading a file macOS keeps only in the cloud downloads it. # The paths are written as in base.json, with ~ for srt to expand # shellcheck disable=SC2088 OPTIONAL_HIDDEN=( "~/Library/Mobile Documents|iCloud Drive" "~/Library/CloudStorage|Nextcloud's and other cloud drives' files" ) # Offered once the sandbox is installed and one of the folders is on this Mac is_installed() { local entry path srt_path > /dev/null || return 1 for entry in "${OPTIONAL_HIDDEN[@]}"; do path="${entry%%|*}" [ -e "${path/#\~/$HOME}" ] && return 0 done return 1 } # Hiding them is the default, so there's nothing you need to do is_configured() { true } # True if agents may read $1 (it's in your config's allowRead) readable() { [ -f "$SANDBOX_CONF" ] \ && json_get '(d.filesystem && d.filesystem.allowRead || []).indexOf(a[0]) >= 0' "$1" \ < "$SANDBOX_CONF" > /dev/null } let_read() { json_edit "$SANDBOX_CONF" ' d.filesystem = d.filesystem || {}; var list = (d.filesystem.allowRead || []).filter(function (p) { return p !== a[0]; }); list.push(a[0]); d.filesystem.allowRead = list;' "$1" } hide() { [ -f "$SANDBOX_CONF" ] || return 0 json_edit "$SANDBOX_CONF" ' if (d.filesystem && d.filesystem.allowRead) { d.filesystem.allowRead = d.filesystem.allowRead.filter(function (p) { return p !== a[0]; }); }' "$1" } run_configure() { local choice i path what state echo "Agents in the sandbox can't read these unless you let them. Changes apply the next" echo "time you start an agent. Claude Code's own sandbox doesn't use this list." while true; do echo for i in "${!OPTIONAL_HIDDEN[@]}"; do IFS='|' read -r path what <<< "${OPTIONAL_HIDDEN[$i]}" if readable "$path"; then state="${YELLOW}agents can read it$RESET"; else state="${GREEN}hidden$RESET"; fi printf " %d) %-28s %s %s\n" $((i + 1)) "$path" "$state" "$what" done echo " q) Done" echo read -rp "Choose one to switch: " choice || return 0 if ! [[ "$choice" =~ ^[0-9]+$ ]] || [ "$choice" -lt 1 ] || [ "$choice" -gt ${#OPTIONAL_HIDDEN[@]} ]; then return 0 fi IFS='|' read -r path what <<< "${OPTIONAL_HIDDEN[$((choice - 1))]}" if readable "$path"; then hide "$path" || return 1 echo "$path is hidden from agents again." elif confirm "Let agents read $path ($what)?"; then let_read "$path" || return 1 echo "Agents can read $path." fi done }