Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(devex): preserve runtime credentials in codex (#121939)

Georgiy Tarasov51739c2e1bf4
diff --git a/.codex/run-with-dotenv.py b/.codex/run-with-dotenv.py
index 91277409e19d..ce2c8daa878d 100644
--- a/.codex/run-with-dotenv.py
+++ b/.codex/run-with-dotenv.py
@@ -91,7 +91,7 @@ def main() -> NoReturn:
raise SystemExit(f"error: .env cannot override protected variables: {', '.join(blocked_names)}")
environment = os.environ.copy()
- environment.update({name: value for name, value in values.items() if value is not None})
+ environment.update({name: value for name, value in values.items() if value is not None and name not in environment})
# argv is the caller's own command line, which with-flox execs directly when no .env is present.
# The .env is the untrusted input, and the blocked-name checks above keep it out of the exec.
# nosemgrep: python.lang.security.audit.dangerous-os-exec-tainted-env-args.dangerous-os-exec-tainted-env-args
diff --git a/.codex/with-flox b/.codex/with-flox
index f980e32a9eb6..b7064e92bbfc 100755
--- a/.codex/with-flox
+++ b/.codex/with-flox
@@ -254,6 +254,24 @@ if [[ "$prepare" -eq 0 ]]; then
protected_environment_names+=(CODEX_SANDBOX_NETWORK_DISABLED)
fi
runtime_env+=("PYTEST_ADDOPTS=${PYTEST_ADDOPTS:--p no:xdist}")
+ # Read runtime credentials at invocation time, never from the toolchain cache.
+ for name in \
+ ANTHROPIC_API_KEY \
+ BRAINTRUST_API_KEY \
+ GH_TOKEN \
+ LLM_GATEWAY_ANTHROPIC_API_KEY \
+ LLM_GATEWAY_OPENAI_API_KEY \
+ MODAL_TOKEN_ID \
+ MODAL_TOKEN_SECRET \
+ OPENAI_API_KEY \
+ POSTHOG_OFFLINE_EVAL_API_KEY \
+ POSTHOG_OFFLINE_EVAL_HOST \
+ POSTHOG_OFFLINE_EVAL_LOCAL_CONFIG \
+ SANDBOX_JWT_PRIVATE_KEY; do
+ if [[ "${!name+x}" ]]; then
+ runtime_env+=("$name=${!name}")
+ fi
+ done
if [[ -n "${TERM:-}" ]]; then
runtime_env+=("TERM=$TERM")
protected_environment_names+=(TERM)