Skip to main content

Overview

Sandbox tools provide file system operations and command execution capabilities in a secure, isolated environment. All operations use absolute paths and support both local and remote sandbox providers.

Virtual Path Mapping

The sandbox uses virtual paths that map to thread-specific directories:
  • /mnt/user-data/workspace/* → Thread workspace directory
  • /mnt/user-data/uploads/* → Thread uploads directory
  • /mnt/user-data/outputs/* → Thread outputs directory
For local sandboxes, these virtual paths are automatically replaced with actual filesystem paths.

bash

Execute a bash command in a Linux environment.

Parameters

str
required
Explain why you are running this command in short words. ALWAYS PROVIDE THIS PARAMETER FIRST.
str
required
The bash command to execute. Always use absolute paths for files and directories.

Usage

  • Use python to run Python code
  • Use pip install to install Python packages
  • Always use absolute paths in commands

Examples

Return Type

Returns a string containing:
  • Command stdout/stderr output
  • Error messages if the command fails

ls

List the contents of a directory up to 2 levels deep in tree format.

Parameters

str
required
Explain why you are listing this directory in short words. ALWAYS PROVIDE THIS PARAMETER FIRST.
str
required
The absolute path to the directory to list.

Examples

Return Type

Returns a string containing:
  • Tree-formatted directory listing (up to 2 levels deep)
  • "(empty)" if directory is empty
  • Error message if directory not found or permission denied

read_file

Read the contents of a text file. Use this to examine source code, configuration files, logs, or any text-based file.

Parameters

str
required
Explain why you are reading this file in short words. ALWAYS PROVIDE THIS PARAMETER FIRST.
str
required
The absolute path to the file to read.
int
Optional starting line number (1-indexed, inclusive). Use with end_line to read a specific range.
int
Optional ending line number (1-indexed, inclusive). Use with start_line to read a specific range.

Examples

Return Type

Returns a string containing:
  • File contents (full or specified line range)
  • "(empty)" if file is empty
  • Error messages for missing files, permission issues, or invalid paths

write_file

Write text content to a file.

Parameters

str
required
Explain why you are writing to this file in short words. ALWAYS PROVIDE THIS PARAMETER FIRST.
str
required
The absolute path to the file to write to. ALWAYS PROVIDE THIS PARAMETER SECOND.
str
required
The content to write to the file. ALWAYS PROVIDE THIS PARAMETER THIRD.
bool
Whether to append to the file instead of overwriting. Default is False.

Examples

Return Type

Returns:
  • "OK" on success
  • Error message on failure (permission denied, invalid path, etc.)

str_replace

Replace a substring in a file with another substring.

Parameters

str
required
Explain why you are replacing the substring in short words. ALWAYS PROVIDE THIS PARAMETER FIRST.
str
required
The absolute path to the file to replace the substring in. ALWAYS PROVIDE THIS PARAMETER SECOND.
str
required
The substring to replace. ALWAYS PROVIDE THIS PARAMETER THIRD.
str
required
The new substring. ALWAYS PROVIDE THIS PARAMETER FOURTH.
bool
Whether to replace all occurrences of the substring. If False (default), the substring must appear exactly once in the file.

Important Notes

  • If replace_all is False (default), the tool expects the substring to appear exactly once
  • Returns an error if the substring is not found or appears multiple times when replace_all=False

Examples

Return Type

Returns:
  • "OK" on success
  • Error message if:
    • String to replace is not found
    • File not found
    • Permission denied
    • Unexpected errors occur

Error Handling

All sandbox tools include comprehensive error handling:
  • SandboxError: Caught and returned as formatted error strings
  • FileNotFoundError: Specific error message with path
  • PermissionError: Permission denied errors with context
  • IsADirectoryError: When path is directory but file expected
  • Generic Exception: Unexpected errors with type and message

Lazy Initialization

Sandbox tools support lazy initialization:
  • Sandbox is acquired on first tool use
  • Thread directories are created automatically
  • State is persisted across tool calls
  • Thread-safety guaranteed by provider locking