langchain.js
    Preparing search index...

    Represents an active sandbox for running commands and file operations.

    This class is typically obtained from SandboxClient.createSandbox() and provides methods for command execution and file I/O within the sandbox environment.

    const sandbox = await client.createSandbox("python-sandbox");
    try {
    const result = await sandbox.run("python --version");
    console.log(result.stdout);
    } finally {
    await sandbox.delete();
    }
    Index

    Properties

    created_at?: string

    Timestamp when the sandbox was created.

    dataplane_url?: string

    URL for data plane operations (file I/O, command execution).

    id?: string

    Unique identifier (UUID). Remains constant even if name changes.

    name: string

    Display name (can be updated).

    template_name: string

    Name of the template used to create this sandbox.

    updated_at?: string

    Timestamp when the sandbox was last updated.

    Methods

    • Delete this sandbox.

      Call this when you're done using the sandbox to clean up resources.

      Returns Promise<void>

      const sandbox = await client.createSandbox("python-sandbox");
      try {
      await sandbox.run("echo hello");
      } finally {
      await sandbox.delete();
      }
    • Read a file from the sandbox.

      Parameters

      • path: string

        File path to read. Supports both absolute paths (e.g., /tmp/file.txt) and relative paths (resolved from /home/user/).

      • timeout: number = 60

        Request timeout in seconds.

      Returns Promise<Uint8Array<ArrayBufferLike>>

      File contents as Uint8Array.

      LangSmithDataplaneNotConfiguredError if dataplane_url is not configured.

      ResourceNotFoundError if the file doesn't exist.

      SandboxOperationError if file read fails.

      SandboxConnectionError if connection to sandbox fails.

      const content = await sandbox.read("/tmp/output.txt");
      const text = new TextDecoder().decode(content);
      console.log(text);
    • Execute a command in the sandbox.

      Parameters

      • command: string

        Shell command to execute.

      • options: RunOptions = {}

        Execution options.

      Returns Promise<ExecutionResult>

      ExecutionResult with stdout, stderr, and exit_code.

      LangSmithDataplaneNotConfiguredError if dataplane_url is not configured.

      SandboxOperationError if command execution fails.

      SandboxConnectionError if connection to sandbox fails.

      SandboxNotReadyError if sandbox is not ready.

      const result = await sandbox.run("echo hello");
      console.log(result.stdout); // "hello\n"
      console.log(result.exit_code); // 0
    • Write content to a file in the sandbox.

      Parameters

      • path: string

        Target file path in the sandbox.

      • content: string | Uint8Array<ArrayBufferLike>

        File content (string or bytes).

      • timeout: number = 60

        Request timeout in seconds.

      Returns Promise<void>

      LangSmithDataplaneNotConfiguredError if dataplane_url is not configured.

      SandboxOperationError if file write fails.

      SandboxConnectionError if connection to sandbox fails.

      await sandbox.write("/tmp/script.py", 'print("Hello!")');