Home / Class/ SandboxIntegrationTests Class — langchain Architecture

SandboxIntegrationTests Class — langchain Architecture

Architecture documentation for the SandboxIntegrationTests class in sandboxes.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  c7d9caae_33e4_653c_1291_3b326431ee9d["SandboxIntegrationTests"]
  2d95e59f_5168_1366_c8c2_e21e157938b5["BaseStandardTests"]
  c7d9caae_33e4_653c_1291_3b326431ee9d -->|extends| 2d95e59f_5168_1366_c8c2_e21e157938b5
  c8292138_c3d5_2c31_8800_94b36cfcc2c9["sandboxes.py"]
  c7d9caae_33e4_653c_1291_3b326431ee9d -->|defined in| c8292138_c3d5_2c31_8800_94b36cfcc2c9
  9837b0ae_434b_46b8_fbfd_2bbd6408694f["sandbox_backend()"]
  c7d9caae_33e4_653c_1291_3b326431ee9d -->|method| 9837b0ae_434b_46b8_fbfd_2bbd6408694f
  fa83df90_9019_1606_a4dc_43cc7373c097["sandbox()"]
  c7d9caae_33e4_653c_1291_3b326431ee9d -->|method| fa83df90_9019_1606_a4dc_43cc7373c097
  900b06f6_e2ce_df83_1f53_b706b8f0739e["has_sync()"]
  c7d9caae_33e4_653c_1291_3b326431ee9d -->|method| 900b06f6_e2ce_df83_1f53_b706b8f0739e
  aa2630a6_727e_c5ce_6b91_bd013c6ff16e["has_async()"]
  c7d9caae_33e4_653c_1291_3b326431ee9d -->|method| aa2630a6_727e_c5ce_6b91_bd013c6ff16e
  64141c7a_72d1_4343_bc26_31f99d465d23["_setup_test_dir()"]
  c7d9caae_33e4_653c_1291_3b326431ee9d -->|method| 64141c7a_72d1_4343_bc26_31f99d465d23
  68fd27a5_9458_f012_4605_0b0c08414020["test_write_new_file()"]
  c7d9caae_33e4_653c_1291_3b326431ee9d -->|method| 68fd27a5_9458_f012_4605_0b0c08414020
  788b068a_7b40_89c6_5750_44f3971118a7["test_read_basic_file()"]
  c7d9caae_33e4_653c_1291_3b326431ee9d -->|method| 788b068a_7b40_89c6_5750_44f3971118a7
  4fd9a616_aa5b_81cd_3e6f_87662bd3fff8["test_edit_single_occurrence()"]
  c7d9caae_33e4_653c_1291_3b326431ee9d -->|method| 4fd9a616_aa5b_81cd_3e6f_87662bd3fff8
  96329b90_cbea_d03b_4f43_8c2cc75a8205["test_ls_info_lists_files()"]
  c7d9caae_33e4_653c_1291_3b326431ee9d -->|method| 96329b90_cbea_d03b_4f43_8c2cc75a8205
  a9c52635_1466_a434_c2eb_c96c79c938e1["test_glob_info()"]
  c7d9caae_33e4_653c_1291_3b326431ee9d -->|method| a9c52635_1466_a434_c2eb_c96c79c938e1
  d76db308_ba8e_5806_cb35_649c60cc2677["test_grep_raw_literal()"]
  c7d9caae_33e4_653c_1291_3b326431ee9d -->|method| d76db308_ba8e_5806_cb35_649c60cc2677
  ecde027d_d143_8101_7572_dd29ad101358["test_upload_single_file()"]
  c7d9caae_33e4_653c_1291_3b326431ee9d -->|method| ecde027d_d143_8101_7572_dd29ad101358

Relationship Graph

Source Code

libs/standard-tests/langchain_tests/integration_tests/sandboxes.py lines 54–403

class SandboxIntegrationTests(BaseStandardTests):
    """Standard integration tests for a `SandboxBackendProtocol` implementation."""

    @pytest.fixture(scope="class")
    def sandbox_backend(
        self, sandbox: SandboxBackendProtocol
    ) -> SandboxBackendProtocol:
        """Provide the sandbox backend under test.

        Resets the shared test directory before yielding.
        """
        sandbox.execute(
            "rm -rf /tmp/test_sandbox_ops && mkdir -p /tmp/test_sandbox_ops"
        )
        return sandbox

    @abstractmethod
    @pytest.fixture(scope="class")
    def sandbox(self) -> Iterator[SandboxBackendProtocol]:
        """Yield a clean sandbox backend and tear it down after the class."""

    @property
    def has_sync(self) -> bool:
        """Whether the sandbox supports sync methods."""
        return True

    @property
    def has_async(self) -> bool:
        """Whether the sandbox supports async methods."""
        return True

    @pytest.fixture(autouse=True)
    def _setup_test_dir(self, sandbox_backend: SandboxBackendProtocol) -> None:
        if not self.has_sync:
            pytest.skip("Sync tests not supported.")
        sandbox_backend.execute(
            "rm -rf /tmp/test_sandbox_ops && mkdir -p /tmp/test_sandbox_ops"
        )

    def test_write_new_file(self, sandbox_backend: SandboxBackendProtocol) -> None:
        """Write a new file and verify it can be read back via command execution."""
        if not self.has_sync:
            pytest.skip("Sync tests not supported.")
        test_path = "/tmp/test_sandbox_ops/new_file.txt"
        content = "Hello, sandbox!\nLine 2\nLine 3"
        result = sandbox_backend.write(test_path, content)
        assert result.error is None
        assert result.path == test_path
        exec_result = sandbox_backend.execute(f"cat {test_path}")
        assert exec_result.output.strip() == content

    def test_read_basic_file(self, sandbox_backend: SandboxBackendProtocol) -> None:
        """Write a file and verify `read()` returns expected contents."""
        if not self.has_sync:
            pytest.skip("Sync tests not supported.")
        test_path = "/tmp/test_sandbox_ops/read_test.txt"
        content = "Line 1\nLine 2\nLine 3"
        sandbox_backend.write(test_path, content)
        result = sandbox_backend.read(test_path)
        assert "Error:" not in result
        assert all(line in result for line in ("Line 1", "Line 2", "Line 3"))

    def test_edit_single_occurrence(
        self, sandbox_backend: SandboxBackendProtocol
    ) -> None:
        """Edit a file and assert exactly one occurrence was replaced."""
        if not self.has_sync:
            pytest.skip("Sync tests not supported.")
        test_path = "/tmp/test_sandbox_ops/edit_single.txt"
        content = "Hello world\nGoodbye world\nHello again"
        sandbox_backend.write(test_path, content)
        result = sandbox_backend.edit(test_path, "Goodbye", "Farewell")
        assert result.error is None
        assert result.occurrences == 1
        file_content = sandbox_backend.read(test_path)
        assert "Farewell world" in file_content
        assert "Goodbye" not in file_content

    def test_ls_info_lists_files(self, sandbox_backend: SandboxBackendProtocol) -> None:
        """Create files and verify `ls_info()` lists them."""
        if not self.has_sync:

Frequently Asked Questions

What is the SandboxIntegrationTests class?
SandboxIntegrationTests is a class in the langchain codebase, defined in libs/standard-tests/langchain_tests/integration_tests/sandboxes.py.
Where is SandboxIntegrationTests defined?
SandboxIntegrationTests is defined in libs/standard-tests/langchain_tests/integration_tests/sandboxes.py at line 54.
What does SandboxIntegrationTests extend?
SandboxIntegrationTests extends BaseStandardTests.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free