feat: add Sandbox abstraction — core only (1/N)#2198
Open
agent-of-mkmeral wants to merge 1 commit intostrands-agents:feature/sandboxfrom
Open
feat: add Sandbox abstraction — core only (1/N)#2198agent-of-mkmeral wants to merge 1 commit intostrands-agents:feature/sandboxfrom
agent-of-mkmeral wants to merge 1 commit intostrands-agents:feature/sandboxfrom
Conversation
Add the core Sandbox interface that decouples tool logic from where code runs. This is the first PR in a series to break up the large PR strands-agents#1968 into the feature/sandbox branch. ## What's included (core abstraction only) ### New: src/strands/sandbox/ - base.py: Sandbox ABC with 6 abstract streaming/file methods + 2 non-streaming convenience wrappers, ExecutionResult/FileInfo/OutputFile/StreamChunk dataclasses - host.py: HostSandbox — native Python file I/O + asyncio subprocess (default) - shell_based.py: ShellBasedSandbox — abstract class for remote environments where only shell access is available (Docker, SSH) - noop.py: NoOpSandbox — raises NotImplementedError for all operations ### Modified - src/strands/__init__.py: Added sandbox exports (Sandbox, HostSandbox, NoOpSandbox, ShellBasedSandbox, ExecutionResult, FileInfo, OutputFile, StreamChunk, StreamType) - src/strands/agent/agent.py: Added sandbox parameter to Agent.__init__, defaults to HostSandbox() via lazy import for backwards compatibility - AGENTS.md: Added sandbox/ to directory structure ### Tests: 151 passing - test_base.py (55): ABC contract, dataclasses, convenience methods - test_host.py (50): Command execution, file I/O, streaming, timeouts - test_adversarial_security.py (27): Path traversal, injection, edge cases - test_adversarial_shared_sandbox.py (13): Shared sandboxes, concurrency - test_agent_sandbox.py (7): Agent integration - test_noop.py (12): NoOpSandbox raises NotImplementedError ## What's NOT included (coming in follow-up PRs) - Vended tools (shell, editor, python_repl) - AgentSkills sandbox integration - CodeActPlugin Part of strands-agents#1968 series → feature/sandbox branch
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.
Summary
Add the core Sandbox interface that decouples tool logic from where code runs. This is the first PR in a series to incrementally merge the large PR #1968 into the
feature/sandboxbranch.Target:
feature/sandbox(notmain)What's Included (Core Abstraction Only)
New:
src/strands/sandbox/base.pySandboxABC — 6 abstract streaming/file methods + 2 non-streaming convenience wrappers,ExecutionResult,FileInfo,OutputFile,StreamChunkdataclasseshost.pyHostSandbox— native Python file I/O +asyncio.create_subprocess_exec(default)shell_based.pyShellBasedSandbox— abstract class for remote environments (Docker, SSH)noop.pyNoOpSandbox— raisesNotImplementedErrorfor all operations__init__.pyModified
src/strands/__init__.pySandbox,HostSandbox,NoOpSandbox,ShellBasedSandbox,ExecutionResult,FileInfo,OutputFile,StreamChunk,StreamTypesrc/strands/agent/agent.pysandboxparameter toAgent.__init__— defaults toHostSandbox()via lazy importAGENTS.mdsandbox/to directory structureTests: 151 passing ✅
test_base.pytest_host.pytest_adversarial_security.pytest_adversarial_shared_sandbox.pytest_agent_sandbox.pytest_noop.pyNotImplementedErrorfor all operationsClass Hierarchy
Usage
What's NOT Included (Coming in Follow-up PRs)
shell,editor,python_replinsrc/strands/vended_tools/Part of #1968 series →
feature/sandboxbranchcc @mkmeral