Repository navigation
FEAT: SandboxRegistry, so targets and scorers share a sandbox by name (part 4) - #4103
Draft
Richard Lundeen (richlundeen) wants to merge 16 commits into
Draft
Richard Lundeen (richlundeen) wants to merge 16 commits into
Richard Lundeen (richlundeen) wants to merge 16 commits into
Conversation
… tool's infrastructure fails - max_tool_rounds (default 10) bounds the previously unbounded tool loop. When it is reached, pending calls are answered as not run and the turn ends with an error response carrying a ToolLoopStop reason. - A tool raises ToolInfrastructureError(invoked=...) when its infrastructure fails; the turn ends once every call in the round has a result, and the model is told only that the tool's infrastructure failed. - ToolLoopStop and ToolLoopStopReason are exported from pyrit.models. - Malformed-argument results include the validation message. Part 1 of 5 of sandboxed code execution. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e adapter - Sandbox (experimental, pyrit._code_execution): an adapter implements a few hooks, and the base class enforces the rules every sandbox follows: one shared session that callers take turns using, within one deadline; retries only when nothing ran; renewal before a session limit; idle close; work that finishes when its caller gives up, and work that never starts once it has; quarantine when a close, reset or cleanup can't be confirmed; and evidence (warnings, partial runs, execution ids). It implements SandboxClient, so ProgramExecutionScorer works with any adapter. - DockerSandboxClient is the example adapter, a call sandbox. Invalid input, including arguments too long for a command line, raises SandboxInputError before anything runs. - FakeSandbox for tests, and a contract-test kit, check_sandbox_contract_async, that adapter authors run against a live sandbox. - ProgramExecutionSource reports a rejected request as unavailable and keeps the sandbox's warnings and execution ids. Part 2 of 5 of sandboxed code execution. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- SandboxRegistry names sandboxes, so every caller shares one Sandbox object, and with it one session, per sandbox. It rejects a name that is taken and a sandbox registered twice; close_all_async closes every registered sandbox. - resolve_sandbox accepts a Sandbox or a registered name. - Re-applying the configuration closes the registered sandboxes before the registries reset, so no session is left open; reset_setup_registries also resets this registry. Part 3 of 5 of sandboxed code execution. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 9, 2026
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Registry replacement can discard cleanup records and quarantine after an unconfirmed sandbox close, allowing a fresh object to register while the old session remains open.
1 open issue
What changed in this PR
Adds named sandbox sharing to PyRIT’s experimental code-execution layer, allowing targets, scorers, and operators to use the same sandbox session. This is the registry stage of the sandboxed-execution stack.
Changes:
- Adds
SandboxRegistryandresolve_sandbox, with duplicate-name and duplicate-identity checks. - Integrates sandbox closure and registry reset into live configuration reapplication.
- Adds registry tests and architecture documentation; the supplied diff also includes prerequisite sandbox and bounded-tool-loop changes.
| File | Description |
|---|---|
| tests/unit/setup/test_reinitialization.py | Tests sandbox closure during configuration reapplication. |
| tests/unit/prompt_target/target/test_tool.py | Updates malformed-argument assertions. |
| tests/unit/prompt_target/target/test_openai_response_target_function_chaining.py | Tests tool-loop limits and infrastructure failures. |
| tests/unit/common/test_lazy_package_imports.py | Checks sandbox exports and import independence. |
| tests/unit/_code_execution/test_sandbox.py | Tests sandbox lifecycle and execution guarantees. |
| tests/unit/_code_execution/test_sandbox_registry.py | Tests registration, lookup, closure, and reset. |
| tests/unit/_code_execution/test_sandbox_contract.py | Tests adapter contract checks. |
| tests/unit/_code_execution/test_docker_client.py | Updates Docker adapter and input-limit tests. |
| tests/unit/_code_execution/local_python_sandbox.py | Provides a local subprocess adapter for tests. |
| tests/integration/score/test_program_execution_scorer_integration.py | Updates cancellation-test timeout configuration. |
| pyrit/setup/initialization.py | Includes sandboxes in setup registry resets. |
| pyrit/setup/configuration_loader.py | Closes registered sandboxes before live replacement. |
| pyrit/score/observation/program_execution_source.py | Handles rejected input and retains execution identifiers. |
| pyrit/prompt_target/openai/openai_response_target.py | Bounds tool execution and handles infrastructure failures. |
| pyrit/prompt_target/common/tool_provider.py | Defines tool infrastructure errors. |
| pyrit/prompt_target/__init__.py | Exports the tool infrastructure error. |
| pyrit/models/target/tool_execution_metadata.py | Defines tool-loop stop metadata. |
| pyrit/models/code_execution.py | Adds sandbox execution identifiers to results. |
| pyrit/models/__init__.py | Exports tool-loop stop models. |
| pyrit/_code_execution/sandbox.py | Implements shared sandbox execution and lifecycle rules. |
| pyrit/_code_execution/sandbox_registry.py | Adds named registration and sandbox resolution. |
| pyrit/_code_execution/sandbox_contract.py | Provides adapter contract checks. |
| pyrit/_code_execution/fake_sandbox.py | Provides an in-memory test sandbox. |
| pyrit/_code_execution/docker_client.py | Adapts Docker execution to the sandbox interface. |
| pyrit/_code_execution/client.py | Defines sandbox errors and updates the client contract. |
| pyrit/_code_execution/__init__.py | Exports sandbox and registry APIs lazily. |
| doc/code/framework.md | Documents sandbox responsibilities and named sharing. |
Review effort: Balanced
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…cement Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Richard Lundeen (richlundeen)
left a comment
Contributor
Author
There was a problem hiding this comment.
Automated review completed. No blocking concerns remain. This review records source coverage; it does not authorize merge.
Richard Lundeen (richlundeen)
added a commit
to richlundeen/PyRIT
that referenced
this pull request
Nov 9, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Integrate only 6053ef3, preserving prior Sandbox and tool-loop repairs and deterministic Docker timeout phase coverage. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Preserve session-owned state, separate routine release from operator recovery, bound each invocation acquisition, and keep program scoring fresh. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Keep automatic idle eviction disabled without suppressing an explicitly requested final close. Isolate exact session-budget selection from host interpreter latency while retaining runtime timeout checks. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…egistry layer Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
Part 4 of 5 of sandboxed code execution. A sandbox that keeps state should be represented by one
Sandboxobject, so that everything using it shares one session and sees the same state: a target's tools, the scorer that checks what they did, and operators. This part adds a registry that names sandboxes, and closes them when the configuration is re-applied.The stack, merged in order:
OpenAIResponseTarget(merged)SandboxClientSandboxToolProvider, withrun_<runtime>toolsSandboxRegistry(this PR, parked until a persistent adapter)SandboxCheckScorer(parked until a persistent adapter)SandboxRegistry(pyrit._code_execution): register each sandbox once, under a name, and refer to it by that name. It rejects a name that's taken and a sandbox registered twice, andclose_all_asynccloses every registered sandbox.resolve_sandboxaccepts aSandboxor a registered name. The tools and the check scorer later in the stack take either.reset_setup_registriesresets this registry too.doc/code/framework.md.🤖 Generated with Claude Code