Let sandboxed agents use mktemp, and keep backups from waiting on prompts

macOS' mktemp uses the per-user temp folder in /var/folders, not TMPDIR,
so the sandbox now allows writing there. The sandbox's settings move out
of it, to Application Support, which the agent can't read or write.

Without Full Disk Access, reading Desktop, Documents, Downloads, other
apps' containers or Photos makes macOS ask, and restic waited for an
answer no one gives at night. The backup now leaves those out until it
has Full Disk Access, as configure backup already said it did.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
David Young
2026-11-11 16:19:21 -07:00
co-authored by Claude Opus 5.5
parent eab26c0888
commit ad97e68db1
4 changed files with 36 additions and 9 deletions
+18 -7
View File
@@ -75,11 +75,17 @@ for file in "$USER_CONFIG/base.json" "$USER_CONFIG/$profile.json"; do
[ -f "$file" ] && configs+=("$file")
done
# Outside the folders the agent may change, so it can't change its own rules.
# Named after this process, as srt replaces it (exec below) and nothing is
# left to remove it afterwards; files whose process has ended are removed here.
SETTINGS_DIR="${TMPDIR:-/tmp}/federated-sandbox"
mkdir -m 700 "$SETTINGS_DIR" 2> /dev/null || [ -d "$SETTINGS_DIR" ] || exit 1
# Outside the folders the agent may change (or read), so it can't change its
# own rules; not in macOS' temp folder, which it may change (below). Named
# after this process, as srt replaces it (exec below) and nothing is left to
# remove it afterwards; files whose process has ended are removed here.
SETTINGS_DIR="$HOME/Library/Application Support/Federated Connector/sandbox-settings"
mkdir -p -m 700 "$SETTINGS_DIR" 2> /dev/null || [ -d "$SETTINGS_DIR" ] || exit 1
# macOS' mktemp, and other macOS tools, use your temp folder in /var/folders
# rather than TMPDIR (which srt points at one of its own), so the agent may
# change that folder too
USER_TEMP="$(getconf DARWIN_USER_TEMP_DIR 2> /dev/null)"
for old in "$SETTINGS_DIR"/*.json; do
pid="${old%.json}"
pid="${pid##*.}"
@@ -111,13 +117,18 @@ function run(argv) {
return a;
}
var out = argv[0], domains = argv[1].split(" ").filter(function (d) { return d; });
var config = argv.slice(2).reduce(function (c, path) { return merge(c, read(path)); }, {});
var userTemp = argv[2];
var config = argv.slice(3).reduce(function (c, path) { return merge(c, read(path)); }, {});
config.network = config.network || {};
merge(config.network, {allowedDomains: domains});
if (userTemp) {
config.filesystem = config.filesystem || {};
merge(config.filesystem, {allowWrite: [userTemp.replace(/\/$/, "")]});
}
if (!$(JSON.stringify(config, null, 2)).writeToFileAtomicallyEncodingError(out, true, $.NSUTF8StringEncoding, null)) {
throw new Error("could not write " + out);
}
}' "$settings" "$FEDERATED_SANDBOX_DOMAINS" "${configs[@]}" > /dev/null; then
}' "$settings" "$FEDERATED_SANDBOX_DOMAINS" "$USER_TEMP" "${configs[@]}" > /dev/null; then
echo "Couldn't read the sandbox config: ${configs[*]}"
exit 1
fi