sdk-python icon indicating copy to clipboard operation
sdk-python copied to clipboard

[BUG] harness: a sandbox that vends a tool named like a harness or consumer tool removes both copies (py + ts)

Open arronbailiss opened this issue 1 week ago • 0 comments

Human Overview

To be filled in by a human (AI-drafted issue, see team/AI_USAGE_POLICY.md).

Checks

  • [x] I have updated to the lastest minor and patch version of Strands
  • [x] I have checked the documentation and this is not expected behavior
  • [x] I have searched ./issues and there are no duplicates of my issue

SDK Language

Python, TypeScript

Strands Version

main @ 794d37c6e (strands-harness and @strands-agents/harness from source); TypeScript also at 7296caba7

Language Runtime Version

Python 3.12.11, Node.js 24.15.0

Operating System

macOS 26.7.3

Installation Method

git clone

Steps to Reproduce

When a sandbox is set, the harness removes every tool name the sandbox vends after initialization (dropSandboxTools in harness-ts/src/agent.ts, _drop_sandbox_tools in harness-py/src/strands_harness/agent.py:204-207). The SDK has already skipped any sandbox tool whose name was taken, so when a sandbox vends a tool with the same name as a harness built-in or a consumer tool, the harness's own tool is the one removed and the agent ends up with neither.

TypeScript:

import { tool, type Tool } from '@strands-agents/sdk'
import { Sandbox } from '@strands-agents/sdk/sandbox'
import { makeShell } from '@strands-agents/sdk/vended-tools/bash'
import { BedrockModel } from '@strands-agents/sdk/models/bedrock'
import { createHarness } from '@strands-agents/harness'
import { z } from 'zod'

const model = new BedrockModel({ region: 'us-east-1', modelId: 'us.anthropic.claude-sonnet-4-20250514-v1:0', maxTokens: 1000 })
const lookup = tool({ name: 'lookup', description: 'consumer tool', inputSchema: z.object({}), callback: () => 'ok' })

class RemoteSandbox extends Sandbox {
  async *executeStreaming(): AsyncGenerator<never> { throw new Error('not used') }
  async *executeCodeStreaming(): AsyncGenerator<never> { throw new Error('not used') }
  async readFile(): Promise<Uint8Array> { throw new Error('not used') }
  async writeFile(): Promise<void> { throw new Error('not used') }
  async removeFile(): Promise<void> { throw new Error('not used') }
  async listFiles(): Promise<never[]> { throw new Error('not used') }
  override getTools(): Tool[] {
    return [
      makeShell(this, { name: 'shell' }),
      tool({ name: 'lookup', description: 'sandbox copy', inputSchema: z.object({}), callback: () => 'sandbox' }),
      makeShell(this, { name: 'sandbox_shell' }),
    ]
  }
}

const names = (agent: { tools: { name: string }[] }) => agent.tools.map((t) => t.name).filter((n) => ['shell', 'lookup', 'sandbox_shell'].includes(n))
const plain = await createHarness({ model, tools: [lookup] })
await plain.initialize()
const withSandbox = await createHarness({ model, tools: [lookup], sandbox: new RemoteSandbox() })
await withSandbox.initialize()
console.log('without sandbox:', names(plain))
console.log('with sandbox:   ', names(withSandbox))

Python:

from strands import tool
from strands.models.model import Model
from strands.sandbox.base import Sandbox
from strands.vended_tools import make_shell
from strands_harness import create_harness

class M(Model):
    def update_config(self, **kw): pass
    def get_config(self): return {"model_id": "us.anthropic.claude-sonnet-4-20250514-v1:0"}
    async def structured_output(self, *a, **k):
        raise NotImplementedError
        yield
    async def stream(self, *a, **k):
        raise NotImplementedError
        yield

@tool
def lookup() -> str:
    """consumer tool"""
    return "ok"

@tool(name="lookup")
def sandbox_lookup() -> str:
    """sandbox copy"""
    return "sandbox"

class RemoteSandbox(Sandbox):
    async def execute_streaming(self, *a, **k):
        raise NotImplementedError
        yield
    async def execute_code_streaming(self, *a, **k):
        raise NotImplementedError
        yield
    async def read_file(self, path, **k): raise NotImplementedError
    async def write_file(self, path, content, **k): raise NotImplementedError
    async def remove_file(self, path, **k): raise NotImplementedError
    async def list_files(self, path, **k): raise NotImplementedError
    def get_tools(self):
        return [make_shell(name="shell"), sandbox_lookup, make_shell(name="sandbox_shell")]

pick = lambda agent: [n for n in agent.tool_names if n in ("shell", "lookup", "sandbox_shell")]
print("without sandbox:", pick(create_harness(model=M(), tools=[lookup])))
print("with sandbox:   ", pick(create_harness(model=M(), tools=[lookup], sandbox=RemoteSandbox())))

Expected Behavior

with sandbox: [ 'shell', 'lookup' ] (Python: ['shell', 'lookup']). Only the tools the sandbox added (sandbox_shell) are dropped; the harness's shell and the consumer's lookup stay.

Actual Behavior

TypeScript:

without sandbox: [ 'shell', 'lookup' ]
with sandbox:    []

Python:

without sandbox: ['shell', 'lookup']
with sandbox:    []

Additional Context

At the pin 7296caba7 the same code is at harness-ts/src/agent.ts:301 and :525.

arronbailiss avatar Nov 20 '26 18:11 arronbailiss