verifiers 0.4.2.dev58__py3-none-any.whl → 0.4.2.dev60__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. verifiers/v1/__init__.py +3 -0
  2. verifiers/v1/agent.py +3 -30
  3. verifiers/v1/cli/debug.py +1 -7
  4. verifiers/v1/cli/validate.py +1 -7
  5. verifiers/v1/configs/runtime.py +19 -6
  6. verifiers/v1/env.py +18 -4
  7. verifiers/v1/envs/agentic_judge/env.py +3 -9
  8. verifiers/v1/envs/best_of_n_judge/env.py +2 -13
  9. verifiers/v1/grading.py +4 -10
  10. verifiers/v1/harness.py +1 -7
  11. verifiers/v1/harnesses/bash/harness.py +0 -1
  12. verifiers/v1/harnesses/browser_use/harness.py +0 -1
  13. verifiers/v1/harnesses/null/harness.py +0 -1
  14. verifiers/v1/interception/__init__.py +7 -5
  15. verifiers/v1/interception/server.py +1 -131
  16. verifiers/v1/mcp/launch.py +65 -92
  17. verifiers/v1/mcp/toolset.py +9 -7
  18. verifiers/v1/rollout.py +0 -1
  19. verifiers/v1/runtimes/__init__.py +2 -0
  20. verifiers/v1/runtimes/backends/custom.py +7 -12
  21. verifiers/v1/runtimes/backends/docker.py +0 -11
  22. verifiers/v1/runtimes/backends/prime.py +0 -13
  23. verifiers/v1/runtimes/base.py +27 -50
  24. verifiers/v1/runtimes/private_network.py +3 -2
  25. verifiers/v1/runtimes/runtime.py +2 -13
  26. verifiers/v1/runtimes/strategies.py +2 -2
  27. verifiers/v1/session.py +0 -5
  28. verifiers/v1/submission.py +4 -13
  29. verifiers/v1/task.py +1 -4
  30. verifiers/v1/tasksets/harbor/taskset.py +1 -5
  31. verifiers/v1/tasksets/nemo_gym/taskset.py +15 -7
  32. verifiers/v1/utils/compile.py +9 -62
  33. {verifiers-0.4.2.dev58.dist-info → verifiers-0.4.2.dev60.dist-info}/METADATA +1 -1
  34. {verifiers-0.4.2.dev58.dist-info → verifiers-0.4.2.dev60.dist-info}/RECORD +37 -37
  35. {verifiers-0.4.2.dev58.dist-info → verifiers-0.4.2.dev60.dist-info}/WHEEL +0 -0
  36. {verifiers-0.4.2.dev58.dist-info → verifiers-0.4.2.dev60.dist-info}/entry_points.txt +0 -0
  37. {verifiers-0.4.2.dev58.dist-info → verifiers-0.4.2.dev60.dist-info}/licenses/LICENSE +0 -0
verifiers/v1/__init__.py CHANGED
@@ -47,6 +47,7 @@ if TYPE_CHECKING:
47
47
  PrimeConfig,
48
48
  PrimeVolume,
49
49
  RuntimeConfig,
50
+ SandboxConfig,
50
51
  )
51
52
  from verifiers.v1.configs.sampling import Sampling, SamplingConfig
52
53
  from verifiers.v1.configs.scoring import ScoringConfig
@@ -261,6 +262,7 @@ _NAME_TO_MODULE = {
261
262
  "ModelRoute": "verifiers.v1.clients",
262
263
  "RouteRejected": "verifiers.v1.clients",
263
264
  "NetworkPolicyConfig": "verifiers.v1.configs.runtime",
265
+ "SandboxConfig": "verifiers.v1.configs.runtime",
264
266
  "PATCH_CAP_BYTES": "verifiers.v1.utils.git",
265
267
  "ParentLink": "verifiers.v1.semantic",
266
268
  "PolicyEvent": "verifiers.v1.trace",
@@ -498,6 +500,7 @@ __all__ = [ # noqa: RUF022 - grouped by public API area
498
500
  "BindMount",
499
501
  "CustomRuntimeConfig",
500
502
  "NetworkPolicyConfig",
503
+ "SandboxConfig",
501
504
  "PrimeConfig",
502
505
  "PrimeVolume",
503
506
  "Env",
verifiers/v1/agent.py CHANGED
@@ -38,7 +38,6 @@ from verifiers.v1.rollout import Rollout, RolloutTimeouts
38
38
  from verifiers.v1.runtimes import (
39
39
  Runtime,
40
40
  RuntimeConfig,
41
- backend_cls,
42
41
  provision_backend,
43
42
  runtime_is_local,
44
43
  )
@@ -96,16 +95,6 @@ def resolve_rollout_timeouts(timeout: TimeoutConfig, task: Task) -> RolloutTimeo
96
95
  )
97
96
 
98
97
 
99
- def _check_artifact_runtime(runtime_config: RuntimeConfig) -> None:
100
- """Artifact collection reads the task's paths out of the box, so the box needs a
101
- filesystem of its own."""
102
- if not backend_cls(runtime_config).SUPPORTS_TASK_IMAGES:
103
- raise TypeError(
104
- "artifact collection requires a runtime with its own filesystem; the "
105
- f"{runtime_config.type} runtime cannot run images"
106
- )
107
-
108
-
109
98
  def _check_borrowed_placement(
110
99
  task: Task, runtime: Runtime, base_config: RuntimeConfig
111
100
  ) -> None:
@@ -146,13 +135,7 @@ def _check_borrowed_placement(
146
135
  )
147
136
  if task.data.image is None:
148
137
  return
149
- if not runtime.backend.SUPPORTS_TASK_IMAGES:
150
- raise TypeError(
151
- f"task {task.data.idx!r} requires image {task.data.image!r}, but the "
152
- f"borrowed {runtime.type} runtime cannot run images; borrow a container "
153
- "box (e.g. agent.provision(task)) or drop the task's image"
154
- )
155
- box_image = getattr(runtime.config, "image", None)
138
+ box_image = runtime.config.image
156
139
  if box_image != task.data.image:
157
140
  logger.warning(
158
141
  "Running task %s in borrowed box %s on its image - the task requires %s "
@@ -609,7 +592,6 @@ class Agent:
609
592
  self.trainable: bool = True
610
593
  self._entered = False
611
594
  self._server: InterceptionServer | None = None
612
- self._warned_resources: set[tuple[str, str]] = set()
613
595
 
614
596
  async def __aenter__(self) -> Self:
615
597
  if self._entered:
@@ -765,8 +747,6 @@ class Agent:
765
747
  attempt: int,
766
748
  ) -> Trace:
767
749
  params = self._rollout_params(task, runtime, dict(shared_tools or {}), route)
768
- if collect_artifacts:
769
- _check_artifact_runtime(params["runtime_config"])
770
750
  run = Rollout(
771
751
  task=task,
772
752
  on_trace=on_trace,
@@ -835,8 +815,6 @@ class Agent:
835
815
  params = self._rollout_params(
836
816
  task, runtime, dict(tools or {}), route or ModelRoute(self.ctx)
837
817
  )
838
- if collect_artifacts:
839
- _check_artifact_runtime(params["runtime_config"])
840
818
  run = Rollout(
841
819
  task=task,
842
820
  has_user=True,
@@ -888,9 +866,7 @@ class Agent:
888
866
  runtime_config = runtime.config
889
867
  run_is_local = runtime.is_local
890
868
  else:
891
- runtime_config = resolve_runtime_config(
892
- self.runtime_config, task, self._warned_resources
893
- )
869
+ runtime_config = resolve_runtime_config(self.runtime_config, task)
894
870
  run_is_local = runtime_is_local(runtime_config)
895
871
  validate_pairing(
896
872
  harness,
@@ -916,7 +892,7 @@ class Agent:
916
892
  """Provision (and on exit tear down) a box from this agent's runtime
917
893
  policy, resolved for `task` when given; share it via `run(..., runtime=runtime)`."""
918
894
  config = (
919
- resolve_runtime_config(self.runtime_config, task, self._warned_resources)
895
+ resolve_runtime_config(self.runtime_config, task)
920
896
  if task is not None
921
897
  else self.runtime_config
922
898
  )
@@ -947,11 +923,8 @@ class _EpisodeAgent(Agent):
947
923
  completed: list[Trace],
948
924
  on_trace: Callable[[Trace], None] | None,
949
925
  on_discard: Callable[[Trace], None] | None,
950
- warned_resources: set,
951
926
  ) -> None:
952
927
  super().__init__(config, interception=interception)
953
- # Resource warnings dedupe env-wide, not per episode.
954
- self._warned_resources = warned_resources
955
928
  self._name = name
956
929
  self._shared_tools = shared_tools
957
930
  self._task_cls = task_cls
verifiers/v1/cli/debug.py CHANGED
@@ -25,7 +25,7 @@ from verifiers.v1.cli.resolve import (
25
25
  with_positional_taskset,
26
26
  )
27
27
  from verifiers.v1.configs.cli.debug import DebugConfig
28
- from verifiers.v1.runtimes import ProgramResult, Runtime, backend_cls, make_backend
28
+ from verifiers.v1.runtimes import ProgramResult, Runtime, make_backend
29
29
  from verifiers.v1.state import state_cls
30
30
  from verifiers.v1.task import Task
31
31
  from verifiers.v1.trace import AgentInfo, Error, Trace, TraceTask
@@ -274,12 +274,6 @@ async def run_debug(config: DebugConfig) -> list[Trace]:
274
274
  f"{type(taskset).__name__} is infinite - bound the run with -n"
275
275
  )
276
276
  tasks = list(taskset)
277
- if not backend_cls(config.runtime).SUPPORTS_TASK_IMAGES and any(
278
- type(t).NEEDS_CONTAINER or t.data.image for t in tasks
279
- ):
280
- raise SystemExit(
281
- "taskset needs a container runtime to debug - pass --runtime.type docker (or prime)"
282
- )
283
277
 
284
278
  out = output_path(config)
285
279
  save_config(config, out, "debug.json")
@@ -35,7 +35,7 @@ from verifiers.v1.grading import (
35
35
  scoring_network,
36
36
  verifier_runtime,
37
37
  )
38
- from verifiers.v1.runtimes import backend_cls, make_backend
38
+ from verifiers.v1.runtimes import make_backend
39
39
  from verifiers.v1.runtimes.deployment import Deployment
40
40
  from verifiers.v1.state import state_cls
41
41
  from verifiers.v1.task import Task
@@ -448,12 +448,6 @@ async def run_validate(config: ValidateConfig) -> list[dict]:
448
448
  f"{type(taskset).__name__} is infinite - bound the run with -n"
449
449
  )
450
450
  tasks = list(taskset)
451
- if not backend_cls(config.runtime).SUPPORTS_TASK_IMAGES and any(
452
- type(t).NEEDS_CONTAINER or t.data.image for t in tasks
453
- ):
454
- raise SystemExit(
455
- "taskset needs a container runtime to validate - pass --runtime.type docker (or prime)"
456
- )
457
451
  mode = validation_mode(config)
458
452
  checks = "gold+noop" if mode == "all" else mode
459
453
  out = output_path(config)
@@ -152,13 +152,28 @@ class NetworkPolicyConfig(BaseConfig):
152
152
  return type(self).model_validate({**values, "allow": allow, "block": block})
153
153
 
154
154
 
155
- class DockerConfig(NetworkPolicyConfig):
156
- type: Literal["docker"] = "docker"
155
+ class SandboxConfig(BaseConfig):
156
+ """What every runtime provisions: a task image with a working directory and the
157
+ resources `TaskData.resources` requests. Network policy support is declared by also
158
+ inheriting `NetworkPolicyConfig`."""
159
+
157
160
  image: str = "python:3.11-slim"
158
161
  workdir: str | None = None
159
162
  """Working directory override; None uses the task's workdir, or /app."""
160
163
  # TaskData.resources uses these units; non-default runtime config values take precedence.
161
164
  cpu: float | None = None
165
+ """CPU cores. None = the provider's default."""
166
+ memory: float | None = None
167
+ """Memory limit in GB. None = the provider's default."""
168
+ gpu: str | None = None
169
+ """GPU spec, e.g. "A100" or "A100:2" (a bare count = provider-chosen type)."""
170
+ disk: float | None = None
171
+ """Disk in GB. None = the provider's default."""
172
+
173
+
174
+ class DockerConfig(SandboxConfig, NetworkPolicyConfig):
175
+ type: Literal["docker"] = "docker"
176
+ cpu: float | None = None
162
177
  """Pin the container to this many CPU cores. None = unlimited."""
163
178
  memory: float | None = None
164
179
  """Hard memory limit in GB. None = unlimited."""
@@ -185,15 +200,13 @@ class PrimeVolume(BaseConfig):
185
200
  read_only: bool = True
186
201
 
187
202
 
188
- class PrimeConfig(NetworkPolicyConfig):
203
+ class PrimeConfig(SandboxConfig, NetworkPolicyConfig):
189
204
  type: Literal["prime"] = "prime"
190
205
  image: str = "python:3.11-slim"
191
206
  """Docker image to run. Any pullable ref works: on the first use of an image, the
192
207
  platform auto-builds the VM image that the sandbox needs from it (~10 minutes)
193
208
  and caches the result, so later sandboxes on the same ref start in
194
209
  seconds."""
195
- workdir: str | None = None
196
- """Working directory override; None uses the task's workdir, or /app."""
197
210
  region: str | None = None
198
211
  """Region to provision in (None = provider-chosen)."""
199
212
  labels: list[str] = Field(default_factory=list)
@@ -242,7 +255,7 @@ class PrimeConfig(NetworkPolicyConfig):
242
255
  return self
243
256
 
244
257
 
245
- class CustomRuntimeConfig(BaseConfig):
258
+ class CustomRuntimeConfig(SandboxConfig):
246
259
  type: Literal["custom"] = "custom"
247
260
  import_path: str
248
261
  """Dotted path to a `RuntimeBackend` subclass, e.g. `my_package.runtime.MyBackend`."""
verifiers/v1/env.py CHANGED
@@ -30,7 +30,8 @@ from verifiers.v1.interception import (
30
30
  requires_tunnel,
31
31
  )
32
32
  from verifiers.v1.mcp import SharedToolServer, serve_shared
33
- from verifiers.v1.runtimes import runtime_is_local
33
+ from verifiers.v1.mcp.launch import check_reachable, tool_runtime
34
+ from verifiers.v1.runtimes import RuntimeConfig, runtime_is_local
34
35
  from verifiers.v1.task import Task
35
36
  from verifiers.v1.trace import Error, Trace, TraceTask
36
37
  from verifiers.v1.utils.format import format_time
@@ -135,7 +136,6 @@ class Env(ABC, Generic[ConfigT]):
135
136
  self._shared_tools: dict[str, SharedToolServer] = {}
136
137
  self._interception: Interception | None = None
137
138
  # Resource warnings dedupe env-wide (agents are per-episode).
138
- self._warned_resources: set = set()
139
139
 
140
140
  # --- the multi-agent surface (override these) ------------------------------
141
141
 
@@ -215,7 +215,6 @@ class Env(ABC, Generic[ConfigT]):
215
215
  completed=completed,
216
216
  on_trace=on_trace,
217
217
  on_discard=on_discard,
218
- warned_resources=self._warned_resources,
219
218
  )
220
219
 
221
220
  agents = Agents(self.config, make)
@@ -437,11 +436,26 @@ class Env(ABC, Generic[ConfigT]):
437
436
  ]
438
437
  return requires_tunnel(self._runs_local(), configs, shared.values())
439
438
 
439
+ def tool_provider(self) -> RuntimeConfig:
440
+ """The runtime shared servers default to: the roles' provider, or a remote role's
441
+ when roles mix providers, since a local server cannot serve a remote harness."""
442
+ runtimes = [spec.runtime for spec in self._agent_specs.values()]
443
+ remote = [config for config in runtimes if not runtime_is_local(config)]
444
+ return (remote or runtimes)[0]
445
+
440
446
  @contextlib.asynccontextmanager
441
447
  async def shared_tools(self):
442
448
  servers = self.taskset.toolsets(self.taskset.config)
443
449
  if not servers:
444
450
  yield {}
445
451
  return
446
- async with serve_shared(servers, harness_is_local=self._runs_local()) as shared:
452
+ provider = self.tool_provider()
453
+ for server in servers:
454
+ if not server.config.url:
455
+ check_reachable(
456
+ server.server_name,
457
+ tool_runtime(server.config, provider),
458
+ self._runs_local(),
459
+ )
460
+ async with serve_shared(servers, provider) as shared:
447
461
  yield shared
@@ -23,7 +23,6 @@ from verifiers.v1.judges.rubric import (
23
23
  score_verdicts,
24
24
  weighted_score,
25
25
  )
26
- from verifiers.v1.runtimes import backend_cls
27
26
  from verifiers.v1.utils.compile import validate_pairing
28
27
 
29
28
  VERDICT_FILE = "/tmp/verdict.json"
@@ -118,10 +117,7 @@ HINT_SECTION = """\
118
117
  class JudgeTask(vf.Task):
119
118
  """The judge's verdict task: the solver task's world mirrored onto the minted
120
119
  row, the trace record written (and any stale verdict removed) before the
121
- judge starts, verdict scraped off the live box after it exits. `NEEDS_CONTAINER`
122
- keeps `Agent.run`'s per-task backstop aligned with the judge's declared need."""
123
-
124
- NEEDS_CONTAINER = True
120
+ judge starts, verdict scraped off the live box after it exits."""
125
121
 
126
122
  def __init__(
127
123
  self,
@@ -276,8 +272,8 @@ class AgenticJudgeEnv(vf.Env[AgenticJudgeEnvConfig]):
276
272
  config.task.criteria()
277
273
 
278
274
  def _check_agents(self) -> None:
279
- """The judge executes real code, never on the host — refuse an impossible
280
- pairing at construction, not after burning a full solver run."""
275
+ """Refuse an impossible judge at construction, not after burning a full
276
+ solver run."""
281
277
  judge = self._harnesses["judge"]
282
278
  if not judge.EXECUTES_CODE:
283
279
  raise ValueError(
@@ -318,8 +314,6 @@ class AgenticJudgeEnv(vf.Env[AgenticJudgeEnvConfig]):
318
314
  workspace = (
319
315
  policy.runtime if policy.mode == "isolated" else None
320
316
  ) or self.config.solver.runtime
321
- if not backend_cls(workspace).SUPPORTS_TASK_IMAGES:
322
- raise TypeError("agentic judging requires a container scoring workspace")
323
317
  validate_pairing(self._harnesses["judge"], JudgeTask, workspace)
324
318
 
325
319
  async def judge(solution: vf.Trace, runtime: vf.Runtime) -> None:
@@ -25,7 +25,6 @@ from verifiers.v1.envs.agentic_judge.env import (
25
25
  TextSource,
26
26
  )
27
27
  from verifiers.v1.envs.best_of_n import BestOfNEnv, BestOfNEnvConfig
28
- from verifiers.v1.runtimes import backend_cls
29
28
  from verifiers.v1.utils.artifacts import _validate_restore
30
29
 
31
30
  ATTEMPTS_DIR = "/tmp/attempts"
@@ -120,9 +119,7 @@ class Ranking(BaseModel):
120
119
  class RankTask(vf.Task):
121
120
  """One judge's ranking task: every attempt's record and artifacts uploaded
122
121
  under its label before the judge starts, the ranking scraped off the box after
123
- it exits. `NEEDS_CONTAINER`: the judge executes code, never on the host."""
124
-
125
- NEEDS_CONTAINER = True
122
+ it exits."""
126
123
 
127
124
  def __init__(self, data: vf.TaskData, labels: dict[str, vf.Trace]) -> None:
128
125
  super().__init__(data)
@@ -246,23 +243,15 @@ class BestOfNJudgeEnv(BestOfNEnv, vf.Env[BestOfNJudgeEnvConfig]):
246
243
  "best-of-n-judge requires a judge harness that can execute code, but "
247
244
  f"harness {judge.config.id!r} is a tool-less chat loop"
248
245
  )
249
- if not backend_cls(config.judge.runtime).SUPPORTS_TASK_IMAGES:
250
- raise ValueError(
251
- "best-of-n-judge requires a container judge runtime: "
252
- "--env.judge.runtime.type docker|prime"
253
- )
254
246
 
255
247
  async def setup(self, agents: vf.Agents) -> None:
256
248
  # The judges grade the policy; their tokens are never training data.
257
249
  agents.judge.trainable = False
258
250
 
259
251
  async def run(self, task: vf.Task, agents: vf.Agents) -> None:
260
- # Artifacts need a runtime with its own filesystem; a subprocess attempt
261
- # is ranked on its trace alone.
262
- collect = backend_cls(self.config.agent.runtime).SUPPORTS_TASK_IMAGES
263
252
  async with asyncio.TaskGroup() as tg:
264
253
  runs = [
265
- tg.create_task(agents.agent.run(task, collect_artifacts=collect))
254
+ tg.create_task(agents.agent.run(task, collect_artifacts=True))
266
255
  for _ in range(self.config.n)
267
256
  ]
268
257
  attempts = [run.result() for run in runs]
verifiers/v1/grading.py CHANGED
@@ -13,7 +13,6 @@ from verifiers.v1.runtimes import (
13
13
  PrimeConfig,
14
14
  Runtime,
15
15
  RuntimeConfig,
16
- backend_cls,
17
16
  )
18
17
  from verifiers.v1.task import Task
19
18
  from verifiers.v1.trace import Error, Trace
@@ -57,26 +56,21 @@ def verifier_runtime(
57
56
  # A task without its own image/workdir inherits the actual workspace's values,
58
57
  # including a Compose image or split execution configuration.
59
58
  task = task.with_data(
60
- image=task.data.image or getattr(solver_runtime.config, "image", None),
61
- workdir=task.data.workdir or getattr(solver_runtime.config, "workdir", None),
59
+ image=task.data.image or solver_runtime.config.image,
60
+ workdir=task.data.workdir or solver_runtime.config.workdir,
62
61
  )
63
62
  if policy.network is not None:
64
63
  task = task.with_data(network=policy.network)
65
64
  config = resolve_runtime_config(source, task)
66
65
  if policy.runtime is not None and "image" in policy.runtime.model_fields_set:
67
66
  config = config.model_copy(update={"image": policy.runtime.image})
68
- if not backend_cls(config).SUPPORTS_TASK_IMAGES:
69
- raise TaskError(
70
- f"isolated verification requires an isolated filesystem; the "
71
- f"{config.type} runtime cannot run images"
72
- )
73
67
  relative = [
74
68
  a.source
75
69
  for a in task.data.artifacts
76
70
  if not PurePosixPath(a.source).is_absolute()
77
71
  ]
78
- solver_dir = PurePosixPath(getattr(solver_runtime.config, "workdir", "/") or "/app")
79
- grader_dir = PurePosixPath(getattr(config, "workdir", "/") or "/app")
72
+ solver_dir = PurePosixPath(solver_runtime.config.workdir or "/app")
73
+ grader_dir = PurePosixPath(config.workdir or "/app")
80
74
  if relative and solver_dir != grader_dir:
81
75
  raise TaskError(
82
76
  f"cannot restore relative artifacts {relative!r} from {solver_dir} into {grader_dir}; use matching workdirs or absolute paths"
verifiers/v1/harness.py CHANGED
@@ -56,17 +56,11 @@ class Harness(ABC, Generic[ConfigT]):
56
56
  EXECUTES_CODE: ClassVar[bool] = True
57
57
  """Whether the program hands the model local execution in the runtime — true for
58
58
  every real harness; the tool-less chat loops (`null`) override to False. Read
59
- where model-directed execution changes the rules: the subprocess-on-host
60
- warning, the judge env's sandbox requirement."""
59
+ where model-directed execution changes the rules, e.g. the judge envs."""
61
60
  SUPPORTS_SKILLS: ClassVar[bool] = False
62
61
  """Whether the program discovers SKILL.md skills — it calls
63
62
  `install_skills` with a run-scoped discovery location; configuring
64
63
  `skills` on a harness without support is rejected up front."""
65
- NEEDS_CONTAINER: ClassVar[bool] = True
66
- """Whether the program must run in a container runtime: True for every harness
67
- that installs and drives a third-party program — on the host (subprocess) it
68
- leaks host state (auth, config, processes) both ways. Only the minimal
69
- in-house loops (`bash`, `null`) override to False."""
70
64
 
71
65
  def __init__(self, config: ConfigT) -> None:
72
66
  self.config = config
@@ -53,7 +53,6 @@ class BashHarness(Harness[BashHarnessConfig]):
53
53
  SUPPORTS_MCP = True
54
54
  SUPPORTS_RESUME = True
55
55
  SUPPORTS_TOOL_INTERCEPTION = True
56
- NEEDS_CONTAINER = False
57
56
 
58
57
  async def setup(self, runtime: Runtime) -> None:
59
58
  await runtime.prepare_uv_script(CHAT_PROGRAM_SOURCE, self.config.resolved_env)
@@ -57,7 +57,6 @@ class BrowserUseHarness(Harness[BrowserUseHarnessConfig]):
57
57
  SUPPORTS_MCP = True
58
58
  SUPPORTS_RESUME = True
59
59
  # The browser tool executes model-authored Python through a third-party daemon.
60
- NEEDS_CONTAINER = True
61
60
 
62
61
  async def setup(self, runtime: Runtime) -> None:
63
62
  await runtime.prepare_uv_script(PROGRAM_SOURCE, self.config.resolved_env)
@@ -28,7 +28,6 @@ class NullHarness(Harness[NullHarnessConfig]):
28
28
  SUPPORTS_RESUME = True
29
29
  SUPPORTS_TOOL_INTERCEPTION = True
30
30
  EXECUTES_CODE = False
31
- NEEDS_CONTAINER = False
32
31
 
33
32
  async def setup(self, runtime: Runtime) -> None:
34
33
  await runtime.prepare_uv_script(CHAT_PROGRAM_SOURCE, self.config.resolved_env)
@@ -32,19 +32,21 @@ def requires_tunnel(
32
32
  """Whether the interception must be exposed via a tunnel — some consumer is off the
33
33
  host network: the harness itself, a live `shared` server in a remote runtime, or a
34
34
  tool server config placing one there (each reaches the `/state` channel from
35
- its own runtime). Task-format adapters share the harness's locality. Skipped as
36
- non-consumers: a config-`url` server (external —
37
- it connects out), and an `external` shared server (outside the state machinery
38
- entirely). False means every consumer reaches the server at localhost."""
35
+ its own runtime). A server without a runtime of its own shares the harness's
36
+ locality, as do task-format adapters. Skipped as non-consumers: a config-`url`
37
+ server (external — it connects out), and an `external` shared server (outside the
38
+ state machinery entirely). False means every consumer reaches the server at
39
+ localhost."""
39
40
  from verifiers.v1.mcp.toolset import BaseToolsetConfig
40
41
 
41
42
  if not harness_is_local:
42
43
  return True
43
- if any(not s.external and not s.local for s in shared):
44
+ if any(s.runtime is not None and not s.runtime.is_local for s in shared):
44
45
  return True
45
46
  return any(
46
47
  isinstance(config, BaseToolsetConfig)
47
48
  and not config.url
49
+ and config.runtime is not None
48
50
  and not runtime_is_local(config.runtime)
49
51
  for config in server_configs
50
52
  )
@@ -30,8 +30,7 @@ import time
30
30
  import traceback
31
31
  from collections.abc import AsyncIterator, Awaitable, Collection, Mapping
32
32
  from contextlib import asynccontextmanager
33
- from dataclasses import dataclass, field
34
- from functools import partial
33
+ from dataclasses import dataclass
35
34
 
36
35
  import httpx
37
36
  from aiohttp import web
@@ -68,7 +67,6 @@ from verifiers.v1.semantic import ACPInfo, extract_acp_info, routing_session_id
68
67
  from verifiers.v1.session import IdempotentRequest, ReplayResponse, RolloutSession
69
68
  from verifiers.v1.trace import Error, ModelCall, PolicyEvent, TimeSpan
70
69
  from verifiers.v1.types import FinishReason, Response, Usage
71
- from verifiers.v1.utils.aio import run_shielded
72
70
  from verifiers.v1.utils.format import format_time
73
71
  from verifiers.v1.utils.logging import clip, get_logger, isolated
74
72
 
@@ -95,25 +93,6 @@ RETRY_COUNT_HEADER = "x-stainless-retry-count"
95
93
  IDEMPOTENCY_KEY_HEADER = "Idempotency-Key"
96
94
  IDEMPOTENCY_CACHE_TTL_SECONDS = 600
97
95
  IDEMPOTENCY_CACHE_MAX_COMPLETED = 64
98
- _HOP_HEADERS = {
99
- "connection",
100
- "keep-alive",
101
- "proxy-authenticate",
102
- "proxy-authorization",
103
- "proxy-connection",
104
- "te",
105
- "trailer",
106
- "transfer-encoding",
107
- "upgrade",
108
- }
109
-
110
-
111
- @dataclass
112
- class _MCPRoute:
113
- session: RolloutSession
114
- url: str
115
- client: httpx.AsyncClient
116
- handlers: set[asyncio.Task] = field(default_factory=set)
117
96
 
118
97
 
119
98
  def is_retried_request(headers: Mapping[str, str]) -> bool:
@@ -363,7 +342,6 @@ class InterceptionServer(Interception):
363
342
  self.clients: dict[str, Client] = {}
364
343
  self.state_sessions: dict[str, RolloutSession] = {}
365
344
  self.state_routes: dict[str, RolloutSession] = {}
366
- self.mcp_routes: dict[str, _MCPRoute] = {}
367
345
  self.state_service_secrets = frozenset(state_service_secrets)
368
346
  self.config = config or InterceptionServerConfig()
369
347
  self.tunnel: Tunnel | None = (
@@ -413,18 +391,13 @@ class InterceptionServer(Interception):
413
391
  self.sessions[model_secret] = session
414
392
  self.state_sessions[state_secret] = session
415
393
  self.state_routes[session.trace.id] = session
416
- session.proxy_mcp = partial(self.proxy_mcp, model_secret)
417
394
  return model_secret, state_secret
418
395
 
419
396
  def unregister(self, model_secret: str, state_secret: str) -> None:
420
397
  session = self.sessions.pop(model_secret, None)
421
398
  self.state_sessions.pop(state_secret, None)
422
399
  if session is not None:
423
- session.proxy_mcp = None
424
400
  self.state_routes.pop(session.trace.id, None)
425
- for capability, route in list(self.mcp_routes.items()):
426
- if route.session is session:
427
- del self.mcp_routes[capability]
428
401
  # The rollout concluded; its trace is sealed. Cancel straggler handlers
429
402
  # (aiohttp keeps them alive past client death) so a slow upstream call
430
403
  # can't commit a late turn onto the concluded trace.
@@ -438,107 +411,6 @@ class InterceptionServer(Interception):
438
411
  finally:
439
412
  self.unregister(model_secret, state_secret)
440
413
 
441
- @asynccontextmanager
442
- async def proxy_mcp(self, model_secret: str, url: str) -> AsyncIterator[str]:
443
- """Expose one fixed host backend with its own capability, revoked before reuse.
444
-
445
- All harnesses accept URLs, including ACP consumers. A fresh URL capability
446
- grants only this MCP endpoint, never the private task/state or model channels.
447
- Only the launcher can register destinations; request paths cannot select one.
448
- """
449
- session = self.sessions[model_secret]
450
- capability = secrets.token_urlsafe(32)
451
- # Long-lived MCP streams use the consumer's timeout and rollout cancellation.
452
- # No redirects, environment proxies, cookies from other routes, or retries.
453
- async with httpx.AsyncClient(
454
- timeout=httpx.Timeout(None, connect=5.0),
455
- limits=httpx.Limits(max_connections=None, max_keepalive_connections=8),
456
- trust_env=False,
457
- ) as client:
458
- route = _MCPRoute(session, url, client)
459
- self.mcp_routes[capability] = route
460
- try:
461
- yield f"{self.base_url.rstrip('/')}/mcp/{capability}"
462
- finally:
463
- self.mcp_routes.pop(capability, None)
464
- handlers = list(route.handlers)
465
- for handler in handlers:
466
- handler.cancel()
467
- await run_shielded(asyncio.gather(*handlers, return_exceptions=True))
468
-
469
- async def handle_mcp(self, request: web.Request) -> web.StreamResponse:
470
- route = self.mcp_routes.get(request.match_info["capability"])
471
- if route is None or route.session.released:
472
- return web.json_response({"error": "unauthorized"}, status=401)
473
- handler = asyncio.current_task()
474
- assert handler is not None
475
- route.session.adopt(handler)
476
- route.handlers.add(handler)
477
- pending = asyncio.create_task(self._forward_mcp(request, route))
478
- try:
479
- # Model handlers intentionally survive disconnects for coalesced retries.
480
- # MCP handlers must instead close even an idle SSE stream on disconnect.
481
- while not pending.done():
482
- await asyncio.wait({pending}, timeout=0.25)
483
- if request.transport is None or request.transport.is_closing():
484
- raise asyncio.CancelledError
485
- return await pending
486
- finally:
487
- pending.cancel()
488
- await run_shielded(asyncio.gather(pending, return_exceptions=True))
489
- route.handlers.discard(handler)
490
-
491
- async def _forward_mcp(
492
- self, request: web.Request, route: _MCPRoute
493
- ) -> web.StreamResponse:
494
- headers = httpx.Headers(request.headers.items())
495
- blocked = _HOP_HEADERS | set(
496
- map(str.strip, headers.get("connection", "").lower().split(","))
497
- )
498
- # aiohttp decodes incoming bodies; HTTPX supplies backend Host and framing.
499
- for name in blocked | {"host", "content-length", "content-encoding"}:
500
- headers.pop(name, None)
501
- upstream = httpx.Request(
502
- request.method,
503
- httpx.URL(route.url).copy_with(
504
- query=request.rel_url.raw_query_string.encode()
505
- ),
506
- headers=headers,
507
- content=request.content.iter_any() if request.can_read_body else b"",
508
- )
509
- stream = web.StreamResponse()
510
- response = None
511
- try:
512
- # send(Request) forwards only this request's headers, without stored cookies.
513
- response = await route.client.send(upstream, stream=True)
514
- stream.set_status(response.status_code)
515
- blocked = _HOP_HEADERS | set(
516
- map(
517
- str.strip, response.headers.get("connection", "").lower().split(",")
518
- )
519
- )
520
- for name, value in response.headers.multi_items():
521
- if name.lower() not in blocked:
522
- stream.headers.add(name, value)
523
- await stream.prepare(request)
524
- async for chunk in response.aiter_raw():
525
- await stream.write(chunk)
526
- await stream.write_eof()
527
- return stream
528
- except httpx.TransportError as error:
529
- if stream.prepared:
530
- # A truncated response is a failed call, never a successful partial result.
531
- if request.transport is not None:
532
- request.transport.close()
533
- return stream
534
- return web.json_response(
535
- {"error": "MCP backend unavailable"},
536
- status=504 if isinstance(error, httpx.TimeoutException) else 502,
537
- )
538
- finally:
539
- if response is not None:
540
- await run_shielded(response.aclose())
541
-
542
414
  def _handler_for(self, dialect: Dialect):
543
415
  """Bind a route's dialect to the request handler — the route the SDK posts to is what
544
416
  selects the wire format (see `dialects.DIALECTS`)."""
@@ -588,8 +460,6 @@ class InterceptionServer(Interception):
588
460
  # A launched tool server fetches its rollout's task here to run `setup_task` — the task
589
461
  # is never passed via env, only over this channel, keyed by the state bearer.
590
462
  app.router.add_get("/task", self.handle_task_get)
591
- app.router.add_route("*", "/mcp/{capability}", self.handle_mcp)
592
- # MCP paths are bearer capabilities, so do not write them to access logs.
593
463
  self.runner = web.AppRunner(app, access_log=None)
594
464
  await self.runner.setup()
595
465
  self.stack.push_async_callback(self.runner.cleanup)