Repository navigation
FEAT: SandboxToolProvider, so a model's tool calls run in a sandbox (part 3) - #4104
Draft
Richard Lundeen (richlundeen) wants to merge 2 commits into
Draft
Richard Lundeen (richlundeen) wants to merge 2 commits into
Richard Lundeen (richlundeen) wants to merge 2 commits into
Conversation
This was referenced Nov 9, 2026
Draft
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Adapter-raised SandboxInputError is returned as a normal result, causing rejected sandbox and file tool calls to be recorded as invoked and potentially scored as executed.
1 open issue
What changed in this PR
Adds SandboxToolProvider, connecting PyRIT’s sandbox execution layer to model tool calls. This fourth part of the stack builds on the sandbox interface, registry, and bounded tool loop.
Changes:
- Exposes runtime execution tools and persistent file operations with validated arguments and bounded results.
- Integrates sandbox failures with tool-loop termination and invocation metadata.
- Adds usage documentation and coverage for tools, adapters, lifecycle behavior, and target integration.
| File | Description |
|---|---|
tests/unit/setup/test_reinitialization.py |
Checks sandbox closure during reinitialization. |
tests/unit/prompt_target/target/test_tool.py |
Checks validation error details. |
tests/unit/prompt_target/target/test_sandbox_tool_provider.py |
Covers sandbox tools and target integration. |
tests/unit/prompt_target/target/test_openai_response_target_function_chaining.py |
Covers loop bounds and infrastructure failures. |
tests/unit/common/test_lazy_package_imports.py |
Extends sandbox import-boundary checks. |
tests/unit/_code_execution/test_sandbox.py |
Covers sandbox lifecycle and execution rules. |
tests/unit/_code_execution/test_sandbox_registry.py |
Covers registration, resolution, and closure. |
tests/unit/_code_execution/test_sandbox_contract.py |
Validates adapter contract checks. |
tests/unit/_code_execution/test_docker_client.py |
Covers Docker capabilities and model tool calls. |
tests/unit/_code_execution/local_python_sandbox.py |
Provides a local subprocess test adapter. |
tests/integration/score/test_program_execution_scorer_integration.py |
Updates cancellation-test timeout configuration. |
pyrit/setup/initialization.py |
Resets the sandbox registry. |
pyrit/setup/configuration_loader.py |
Closes sandboxes before reinitialization. |
pyrit/score/observation/program_execution_source.py |
Handles rejected input and preserves execution identifiers. |
pyrit/prompt_target/openai/openai_response_target.py |
Bounds tool rounds and handles infrastructure failures. |
pyrit/prompt_target/common/tool_provider.py |
Defines infrastructure errors with invocation status. |
pyrit/prompt_target/common/sandbox_tool_provider.py |
Implements sandbox runtime and file tools. |
pyrit/prompt_target/__init__.py |
Exports the provider and infrastructure error. |
pyrit/models/target/tool_execution_metadata.py |
Adds tool-loop stop metadata. |
pyrit/models/code_execution.py |
Adds sandbox execution identifiers. |
pyrit/models/__init__.py |
Exports tool-loop metadata types. |
pyrit/_code_execution/sandbox.py |
Defines shared execution and lifecycle behavior. |
pyrit/_code_execution/sandbox_registry.py |
Registers and resolves shared sandboxes. |
pyrit/_code_execution/sandbox_contract.py |
Provides adapter contract checks. |
pyrit/_code_execution/fake_sandbox.py |
Provides a configurable 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 APIs lazily. |
doc/myst.yml |
Adds the sandboxed tool-calls page to navigation. |
doc/code/targets/12_sandboxed_tool_calls.md |
Documents tools, configuration, and adapter development. |
doc/code/framework.md |
Clarifies target and sandbox responsibilities. |
Review effort: Balanced
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 10, 2026
Integrate microsoft#4104 at f10c809 while retaining the final-layer tool-to-check-scorer integration test. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Richard Lundeen (richlundeen)
added a commit
to richlundeen/PyRIT
that referenced
this pull request
Nov 10, 2026
Integrate microsoft#4104 at58d45c3ab7de35f55b7e3b11772ed69ddbc18531, including selected main6053ef39563941c7e06d26a94de3f9ea41bff86b. Preserve the lower SESSION/fresh-source contracts and upper check-scorer docs/test; its reproduced stateful acquisition compatibility repair follows separately. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…on for SandboxClient SandboxClient gains get_capabilities(), which declares a client's runtimes and per-call limits (input and argument size, output size, default and maximum timeout), and execute_async gains an optional timeout_seconds. A request that does not fit raises SandboxInputError (a ValueError) before anything runs; SandboxCapabilities.validate_request performs the check so adapters share it. DockerSandboxClient implements the extended contract. Its configured timeout is both the default and the limit, and it accepts at most 16 KiB of arguments per run, since they go on a command line. ProgramExecutionSource records a request the sandbox rejects as unavailable evidence, so the verdict is undetermined. Each invocation still runs in a fresh environment; stateful sandboxes are left for the change that adds the first persistent adapter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SandboxToolProvider turns any SandboxClient into run_<runtime> tools, such as run_python. Arguments are checked against the sandbox's declared capabilities before anything runs, so a rejected call goes back to the model and is never recorded as invoked. A sandbox's own input rejection raises the new ToolInputError with the same no-run guarantee, and OpenAIResponseTarget returns its reason to the model without ending the turn. A sandbox failure raises ToolInfrastructureError, so the target ends the turn instead of asking the model to fix infrastructure. RuntimeProfile gains tool_name and description, and SandboxCapabilities gains a description, so the tools can name and describe runtimes to the model. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Richard Lundeen (richlundeen)
force-pushed
the
richlundeen-sandbox-stack-4-tool-provider
branch
from
November 10, 2026 22:50
58d45c3 to
6704b83
Compare
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 3 of 5 of sandboxed code execution. This part gives a model tools that run its code in a sandbox. They work with any target whose tool loop is bounded, starting with
OpenAIResponseTarget.The stack, merged in order:
OpenAIResponseTarget(merged)SandboxClientSandboxToolProvider, withrun_<runtime>tools (this PR)SandboxRegistry(parked until a persistent adapter)SandboxCheckScorer(parked until a persistent adapter)Rescoped with #4102: this part offers
run_<runtime>tools on anySandboxClient. File tools (write_file,read_file,list_dir) and lookup by registered name need a sandbox that keeps state, so they move to the change that adds the first persistent adapter.SandboxToolProvider(sandbox=...)(pyrit.prompt_target) turns a sandbox client into onerun_<runtime>tool per runtime (run_python, …).RuntimeProfilegainstool_nameanddescription, andSandboxCapabilitiesgains adescription, so tools can name and describe runtimes to the model.max_output_chars, and marked when cut), whether the program timed out or hit a resource limit, and how long it took. A program that fails is an ordinary result the model can read and fix.ToolInputError: a sandbox's own input rejection reaches the model with the same no-run guarantee, andOpenAIResponseTargetlets the model correct the call without ending the turn.ToolInfrastructureError, so the target ends the turn instead of asking the model to fix it.doc/code/targets/12_sandboxed_tool_calls.md, and the Targets section ofdoc/code/framework.md.🤖 Generated with Claude Code