Files
docker-agent-sandbox/docker_agent_sandbox/tools/list_dir.py
Matte23 80c2f9b159 feat: Initial library extraction from PIN LLM benchmark
DockerSandbox + LangChain file/shell tools extracted into a standalone package.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-02 11:47:44 +02:00

33 lines
951 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""list_dir.py tool for listing directory contents inside the sandbox."""
from __future__ import annotations
from shlex import quote
from typing import TYPE_CHECKING
from langchain_core.tools import BaseTool, tool
from loguru import logger
if TYPE_CHECKING:
from docker_agent_sandbox.sandbox import DockerSandbox
def make_list_dir_tool(sandbox: "DockerSandbox") -> BaseTool:
"""Return a list_dir tool bound to *sandbox*."""
@tool
def list_dir(path: str = ".") -> str:
"""
List the contents of a directory at *path*.
Returns ``ls -lA`` output,
or an error message if the path does not exist or is not a directory.
"""
logger.debug("Listing files inside sandbox: {}", path)
exit_code, output = sandbox.exec(f"ls -lA -- {quote(path)}")
if exit_code != 0:
return f"[ERROR listing {path!r}] {output.strip()}"
return output
return list_dir