: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(tasks): put the sandbox network policy on the task profile (#125262)
Charles Vien8b0cd4387ca0
diff --git a/products/business_knowledge/backend/sandbox.py b/products/business_knowledge/backend/sandbox.pyindex c75ec28fce8b..89d1d5d6d2c3 100644--- a/products/business_knowledge/backend/sandbox.py+++ b/products/business_knowledge/backend/sandbox.py@@ -253,14 +253,15 @@ def start_sandbox_run(_admit_one_run_per_owner(team.id, user_id)else:admit()+ network = task_profiles.BUSINESS_KNOWLEDGE.networkenv_id = tasks_facade.upsert_internal_sandbox_env(team.id,BUSINESS_KNOWLEDGE_SANDBOX_ENV_NAME,- tasks_facade.SandboxNetworkAccessLevel.CUSTOM,+ tasks_facade.SandboxNetworkAccessLevel(network.levels[0]),private=False,internal=True,- allowed_domains=[],- include_default_domains=False,+ allowed_domains=list(network.allowed_domains),+ include_default_domains=network.include_default_domains,)always_on = format_always_on_context(get_always_on_context(team.id))created = tasks_facade.create_and_run_task(diff --git a/products/business_knowledge/backend/task_profiles.py b/products/business_knowledge/backend/task_profiles.pyindex 794f3e1a65fa..3dc174c1f174 100644--- a/products/business_knowledge/backend/task_profiles.py+++ b/products/business_knowledge/backend/task_profiles.py@@ -2,6 +2,8 @@ from products.tasks.backend.facade.profiles import (AccessGate,DrivePolicy,GithubResolution,+ NetworkAccess,+ NetworkPolicy,OAuthApp,PrAuthorship,Read,@@ -26,6 +28,7 @@ BUSINESS_KNOWLEDGE = TaskProfile(warm=None,runtimes=("acp",),sandbox_templates=("default_base",),+ network=NetworkPolicy(levels=(NetworkAccess.CUSTOM,)),inherit_user_defaults=False,personal_mcp=False,mcp_agent=None,diff --git a/products/tasks/backend/facade/profiles.py b/products/tasks/backend/facade/profiles.pyindex aafdd300ffb4..94a0d875e747 100644--- a/products/tasks/backend/facade/profiles.py+++ b/products/tasks/backend/facade/profiles.py@@ -56,6 +56,12 @@ class GithubAccess(StrEnum):WRITE = "write"+class NetworkAccess(StrEnum):+ TRUSTED = "trusted"+ FULL = "full"+ CUSTOM = "custom"++class SourceKind(StrEnum):SIGNAL_REPORT = "signal_report"HOG_FLOW = "hog_flow"@@ -81,6 +87,17 @@ class WarmPolicy:feature_flag: str | None+@frozen+class NetworkPolicy:+ levels: tuple[NetworkAccess, ...]+ allowed_domains: tuple[str, ...] = ()+ include_default_domains: bool = False++ def __post_init__(self) -> None:+ if not self.levels:+ raise TaskProfileError("A network policy needs at least one level")++@frozenclass TaskProfile:"""The limits and defaults for one kind of task.@@ -133,6 +150,8 @@ class TaskProfile:runtimes: tuple[str, ...]# The sandbox templates a task may boot from. The first one is the default.sandbox_templates: tuple[str, ...]+ # A user-picked sandbox environment overrides this, so it covers internal environments and runs without one.+ network: NetworkPolicy# True applies the creator's and the team's default model settings to each run.inherit_user_defaults: bool# True also installs the creator's personal MCP servers. It has no effect whendiff --git a/products/tasks/backend/temporal/process_task/activities/get_task_processing_context.py b/products/tasks/backend/temporal/process_task/activities/get_task_processing_context.pyindex 59d92b4fb4e2..318ae5d3c560 100644--- a/products/tasks/backend/temporal/process_task/activities/get_task_processing_context.py+++ b/products/tasks/backend/temporal/process_task/activities/get_task_processing_context.py@@ -329,7 +329,8 @@ class TaskProcessingContext:signals-origin runs, whose inference is unbilled and which therefore get their own(longer) ceiling, resolved activity-side into the field below. Autonomous runs getthe cap as a safety net unless the setting disables it deployment-wide. A task with- a profile takes both the exemption and the cap from the profile's `max_wake_minutes`.+ a profile takes the exemption from the profile's `max_wake_minutes`. Its cap is the+ lower of `max_wake_minutes` and the setting."""if self.mode == "interactive" or self._exempt_from_max_run_duration():if self.interactive_max_run_duration_seconds:@@ -338,7 +339,7 @@ class TaskProcessingContext:cap = resolve_max_run_duration()if cap is None or self.profile_max_wake_minutes is None:return cap- return timedelta(minutes=self.profile_max_wake_minutes)+ return min(cap, timedelta(minutes=self.profile_max_wake_minutes))def _exempt_from_max_run_duration(self) -> bool:if self.profile_key:diff --git a/products/tasks/backend/temporal/process_task/tests/test_max_run_duration.py b/products/tasks/backend/temporal/process_task/tests/test_max_run_duration.pyindex 101ee2d69da7..48306e02a989 100644--- a/products/tasks/backend/temporal/process_task/tests/test_max_run_duration.py+++ b/products/tasks/backend/temporal/process_task/tests/test_max_run_duration.py@@ -78,6 +78,7 @@ class TestMaxRunDuration:None,),("setting_disables_profile_cap", "background", Task.OriginProduct.WORKFLOW.value, 120, 0, None),+ ("setting_below_profile_cap", "background", Task.OriginProduct.WORKFLOW.value, 120, 3600, 60),])def test_profile_sets_the_cap(