: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(dev): add POSTHOG_DEV_SANDBOX_EXCLUDE to opt procs out of the dev sandbox (#62744)
Georges-Antoine Assi60eb2ceaf20a
diff --git a/tools/hogli-commands/hogli_commands/devenv/generator.py b/tools/hogli-commands/hogli_commands/devenv/generator.pyindex 1394a0c2f94a..6b488d4f8cf2 100644--- a/tools/hogli-commands/hogli_commands/devenv/generator.py+++ b/tools/hogli-commands/hogli_commands/devenv/generator.py@@ -193,7 +193,7 @@ class MprocsGenerator(ConfigGenerator):proc_config = self._add_uv_groups(proc_config, resolved)# Wrap Python/Node service commands in the dev sandbox when opted in- proc_config = self._add_sandbox_wrapper(proc_config)+ proc_config = self._add_sandbox_wrapper(proc_config, name)# Add logging wrapper if enabledif source_config and source_config.log_to_files:@@ -391,7 +391,7 @@ printf ' {gray}Run {reset}{blue}hogli dev:setup{reset}{gray} to tailor this to# code, so running them unsandboxed doesn't widen the untrusted attack surface._SANDBOX_DOCKER_GATES = ("bin/wait-for-docker", "bin/wait-for-postgres-tables")- def _add_sandbox_wrapper(self, proc_config: dict[str, Any]) -> dict[str, Any]:+ def _add_sandbox_wrapper(self, proc_config: dict[str, Any], name: str = "") -> dict[str, Any]:"""Wrap a service command in bin/dev-sandbox (macOS Seatbelt) when opted in.Opt in globally with POSTHOG_DEV_SANDBOX=1 (e.g. in .env.local). A proc is@@ -403,6 +403,12 @@ printf ' {gray}Run {reset}{blue}hogli dev:setup{reset}{gray} to tailor this toa malicious dependency can't read credentials (~/.ssh, ~/.aws, ...) and deniesthe docker/agent sockets so it can't escape via a container mount.+ POSTHOG_DEV_SANDBOX_EXCLUDE (comma-separated proc names) opts individual+ procs back out. Use sparingly — it exists for procs whose feature set+ requires the docker socket the profile denies, e.g. temporal-worker running+ PostHog Code tasks with SANDBOX_PROVIDER=docker. Excluded procs run fully+ unsandboxed, so the dependency-isolation guarantee no longer covers them.+The docker-gate preamble (bin/wait-for-docker) is peeled out to rununsandboxed, since it needs the very socket the sandbox denies; the actualserver (which reaches infra over TCP) is what gets sandboxed. bin/dev-sandbox@@ -411,7 +417,8 @@ printf ' {gray}Run {reset}{blue}hogli dev:setup{reset}{gray} to tailor this to# `sandbox` is a registry-only selector; pop it so it never leaks into the# emitted proc config (which phrocs/mprocs would otherwise see).should_sandbox = bool(proc_config.pop("sandbox", False))- if os.getenv("POSTHOG_DEV_SANDBOX") != "1" or not should_sandbox:+ excluded = {p.strip() for p in os.getenv("POSTHOG_DEV_SANDBOX_EXCLUDE", "").split(",") if p.strip()}+ if os.getenv("POSTHOG_DEV_SANDBOX") != "1" or not should_sandbox or (name and name in excluded):return proc_configshell = proc_config.get("shell", "")diff --git a/tools/hogli-commands/hogli_commands/tests/test_devenv.py b/tools/hogli-commands/hogli_commands/tests/test_devenv.pyindex aa939ba226fe..dd56cd6acc1c 100644--- a/tools/hogli-commands/hogli_commands/tests/test_devenv.py+++ b/tools/hogli-commands/hogli_commands/tests/test_devenv.py@@ -150,6 +150,16 @@ class TestSandboxWrapper:assert result["shell"] == "bin/dev-sandbox ./bin/start-frontend"assert "sandbox" not in result+ def test_excluded_proc_left_unwrapped(self, monkeypatch: Any) -> None:+ monkeypatch.setenv("POSTHOG_DEV_SANDBOX", "1")+ monkeypatch.setenv("POSTHOG_DEV_SANDBOX_EXCLUDE", "temporal-worker, other-proc")+ generator = MprocsGenerator(MockRegistry({}))+ excluded = generator._add_sandbox_wrapper({"shell": "./run-worker", "sandbox": True}, "temporal-worker")+ assert excluded["shell"] == "./run-worker"+ assert "sandbox" not in excluded+ wrapped = generator._add_sandbox_wrapper({"shell": "./bin/start-backend", "sandbox": True}, "backend")+ assert wrapped["shell"] == "bin/dev-sandbox ./bin/start-backend"+def test_docker_gate_runs_outside_sandbox(self, monkeypatch: Any) -> None:monkeypatch.setenv("POSTHOG_DEV_SANDBOX", "1")result = self._wrap({"shell": "bin/wait-for-docker && ./bin/start-backend", "sandbox": True})