Skip to content

Conversation

@dbschmigelski
Copy link
Member

@dbschmigelski dbschmigelski commented Jul 16, 2025

Description

This pull request introduces a Code Interpreter tool that provides secure, isolated sandbox environments for executing code in multiple programming languages
including Python, JavaScript, and TypeScript. The implementation follows a modular architecture with clear separation of concerns between the tool interface, platform abstraction, and underlying execution engines.

The core design centers around a wrapper class pattern that encapsulates platform lifecycle management while exposing a clean tool interface through the Strands @tool decorator. This wrapper approach was chosen to provide stateful tool functionality, allowing the tool to maintain persistent sessions and manage platform resources
automatically:

class CodeInterpreter(ABC):

    @tool
    def code_interpreter(self, code_interpreter_input: CodeInterpreterInput) -> Dict[str, Any]:
        # Route to appropriate platform method based on action type

The CodeInterpreter class handles initialization, cleanup, and auto-start functionality, ensuring that users don't need to manually manage platform lifecycle while still providing explicit control when needed.

The implementation leverages Pydantic models extensively for input validation and type safety. Rather than using a single schema with numerous optional fields that would require complex runtime validation logic, we opted for discriminated unions with specific action models:

Instead of this complex approach with runtime validation:

class CodeInterpreterInput(BaseModel):
    action_type: str
    session_name: Optional[str] = None
    code: Optional[str] = None
    language: Optional[str] = None
    # ... many optional fields requiring validation logic

We use discriminated unions with specific models:

class ExecuteCodeAction(BaseModel):
    type: Literal["executeCode"]
    session_name: str  # Required
    code: str         # Required
    language: LanguageType  # Required enum
    clear_context: Optional[bool] = False

This approach provides several key benefits: type checking ensures correctness, each action type has clearly defined required and optional fields, validation errors are specific and actionable, and the code is self-documenting through the type system. The Pydantic approach eliminates the need for manual validation code that would be error-prone and difficult to maintain.

Platform abstraction is achieved through the CodeInterpreter base class, which defines a consistent interface that any execution backend must implement. This modular design enables seamless integration of different execution environments. The current implementation include an AgentCoreCodeInterpreter for AWS-based sandbox execution, but the architecture readily supports additional platforms. A local platform could be implemented using Docker containers or virtual environments, while third-party platforms like CodeSandbox.io or custom Kubernetes-based solutions could be integrated by simply implementing the platform protocol.

Related Issues

[Link to related issues using #issue-number format]

Documentation PR

[Link to related associated PR in the agent-docs repo]

Type of Change

  • New Tool

Testing

[How have you tested the change?]

  • hatch fmt --linter
  • hatch fmt --formatter
  • hatch test --all

Checklist

  • I have read the CONTRIBUTING document

  • I have added tests that prove my fix is effective or my feature works

  • I have updated the documentation accordingly

  • I have added an appropriate example to the documentation to outline the feature

  • My changes generate no new warnings

  • Any dependent changes have been merged and published

  • By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@dbschmigelski dbschmigelski requested a review from a team as a code owner July 16, 2025 19:12
@dbschmigelski dbschmigelski merged commit 5599b6e into strands-agents:main Jul 16, 2025
14 of 28 checks passed
cagataycali added a commit that referenced this pull request Jul 21, 2025
* test(load_tool): add e2e test for load tool

* test(load_tool): update providing tool path

* Update calculator tests to not use .invoke as 0.3.0 removed it (#132)

Co-authored-by: Mackenzie Zastrow <zastrowm@users.noreply.github.com>

* fix(a2a): prefix tools and updated default timeout (#134)

Co-authored-by: jer <jerebill@amazon.com>

* feat: add HTML to markdown conversion for http_request tool (#63)

* feat: add HTML to markdown conversion for http_request tool

- Add markdownify and readabilipy dependencies
- Add convert_to_markdown parameter to http_request tool
- Automatically detect and convert HTML responses to markdown
- Add tests and documentation with usage examples

---------

Co-authored-by: Murat Kaan Meral <murmeral@amazon.nl>

* feat: Add handoff to user tool (#142)

* remove references to max_parallel_tools (#144)

* Chore: Remove Preview (#141)

Chore: update contributions doc to reflect community driven status

* Chore: bump to require v1.0.0 (#145)

* feat: migrate multi-agent tools to sdk native patterns and model support (#143)

* feat: Major refactor - Migrate to Strands SDK native patterns & add comprehensive model support

🚀 Overview:
- Migrate custom implementations to native Strands SDK patterns
- Add comprehensive model provider support (9+ providers)
- Enhance reliability, performance, and user experience
- Maintain backward compatibility

🔄 Key Changes:
- agent_graph.py → graph.py (SDK GraphBuilder integration)
- use_llm.py → use_agent.py (enhanced nested agent creation)
- Complete swarm tool architecture overhaul
- Enhanced think tool with model switching
- Production-ready workflow orchestration
- New model utilities system in src/strands_tools/models/

📊 Impact:
- Files Changed: 25+ files
- Lines Added: ~2,000 lines
- Lines Removed: ~1,100 lines
- New model providers: Bedrock, Anthropic, LiteLLM, LlamaAPI, Ollama, OpenAI, Writer, Cohere, GitHub
- 700+ test cases covering new functionality

✅ Backward compatibility maintained with gradual migration path

* fix(deps): convert SSH git URLs to HTTPS for GitHub runner compatibility

- Changed git+ssh://git@github.com URLs to git+https://github.com URLs
- Fixes git clone failures in CI/CD environments that lack SSH key access
- Updated both main dependencies and hatch-static-analysis dependencies

* feat: restore deprecated tools for backward compatibility and update deps

- Add use_llm and agent_graph tools back with deprecation warnings
- These tools will be removed in next major release
- Move Stability AI documentation to docs/stability_ai_tool.md
- Update pyproject.toml dependencies to use proper version ranges
- Add comprehensive test suites for both deprecated tools
- Maintain backward compatibility while guiding users to new APIs

* build: replace git dependency with version constraint for strands-agents

* refactor(models): move models to utils/models directory

- Move all model files from strands_tools/models/ to strands_tools/utils/models/
- Update import statements in graph.py, think.py, use_agent.py, and workflow.py
- Reorganize codebase structure for better organization

* fix(deps): remove duplicate strands-agents dependency

- Removed duplicate strands-agents[a2a] dependency from pyproject.toml
- Keeps only the base strands-agents dependency

---------

Co-authored-by: Arron <139703460+awsarron@users.noreply.github.com>

* build(pyproject): update development status classifier (#146)

* Add AgentCoreMemoryToolProvider for AgentCore Memory Service Integration (#147)

* feat: add Bedrock AgentCore Code Interpreter tool (#148)

* feat: add Bedrock AgentCore Browser Tool (#149)

* Add community-driven call out to the top of the file (#151)

We do the same further down, but you have to jump past the list of tools + environment variables to see it, so making it more prominent towards the top of the readme.

Co-authored-by: Mackenzie Zastrow <zastrowm@users.noreply.github.com>

* test(load_tool): add e2e test for load tool

* test(load_tool): update providing tool path

* test(load_tool): fix naming consistency

---------

Co-authored-by: Jack Yuan <jackypc@amazon.com>
Co-authored-by: Mackenzie Zastrow <3211021+zastrowm@users.noreply.github.com>
Co-authored-by: Mackenzie Zastrow <zastrowm@users.noreply.github.com>
Co-authored-by: Jeremiah <jbill7696@gmail.com>
Co-authored-by: jer <jerebill@amazon.com>
Co-authored-by: Murat Kaan Meral <muratkaanmeral@gmail.com>
Co-authored-by: Murat Kaan Meral <murmeral@amazon.nl>
Co-authored-by: Patrick Gray <pgrayy@amazon.com>
Co-authored-by: Jonathan Segev <jsegev01@gmail.com>
Co-authored-by: ./c² <cagataycali@icloud.com>
Co-authored-by: Arron <139703460+awsarron@users.noreply.github.com>
Co-authored-by: mehtarac <mehtarac@amazon.com>
Co-authored-by: Dean Schmigelski <dbschmigelski+github@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants