summaryrefslogtreecommitdiff
path: root/scripts/sandbox_command.sh
diff options
context:
space:
mode:
authorOlcan <[email protected]>2025-04-24 08:58:47 -0700
committerGitHub <[email protected]>2025-04-24 08:58:47 -0700
commit30bdef9bf54ec3215026643fea957334eb5c00ae (patch)
tree4cd77967961c6411ba673d5ac52babdbb97ce5f9 /scripts/sandbox_command.sh
parentfb1c67219d3bfb9d4193b4f9c0c60e2969657132 (diff)
in sandboxed run scripts, allow .env to be an in any ancestor directory, same as in findEnvFile; also prep for sanboxing with global command (#147)
Diffstat (limited to 'scripts/sandbox_command.sh')
-rwxr-xr-xscripts/sandbox_command.sh13
1 files changed, 12 insertions, 1 deletions
diff --git a/scripts/sandbox_command.sh b/scripts/sandbox_command.sh
index 81775db6..03163458 100755
--- a/scripts/sandbox_command.sh
+++ b/scripts/sandbox_command.sh
@@ -32,7 +32,17 @@ shift $((OPTIND - 1))
# if GEMINI_CODE_SANDBOX is not set, try to source .env in case set there
-if [ -z "${GEMINI_CODE_SANDBOX:-}" ] && [ -f .env ]; then source .env; fi
+# allow .env to be in any ancestor directory (same as findEnvFile in config.ts)
+if [ -z "${GEMINI_CODE_SANDBOX:-}" ]; then
+ current_dir=$(pwd)
+ while [ "$current_dir" != "/" ]; do
+ if [ -f "$current_dir/.env" ]; then
+ source "$current_dir/.env"
+ break
+ fi
+ current_dir=$(dirname "$current_dir")
+ done
+fi
# if GEMINI_CODE_SANDBOX is still not set, then exit immediately w/ code 1
if [ -z "${GEMINI_CODE_SANDBOX:-}" ]; then exit 1; fi
@@ -40,6 +50,7 @@ if [ -z "${GEMINI_CODE_SANDBOX:-}" ]; then exit 1; fi
# lowercase GEMINI_CODE_SANDBOX
GEMINI_CODE_SANDBOX=$(echo "${GEMINI_CODE_SANDBOX:-}" | tr '[:upper:]' '[:lower:]')
+# if GEMINI_CODE_SANDBOX is set to 0 or false, then exit immediately w/ code 1
if [[ "${GEMINI_CODE_SANDBOX:-}" =~ ^(0|false)$ ]]; then
exit 1
fi