Skip to main content

Search file names

matches = sandbox.files.search_files("/workspace", "*.py")
for path in matches:
    print(path)

Search file contents

for match in sandbox.files.find_files("/workspace", "TODO"):
    print(match.file, match.line, match.content)

Replace text

paths = sandbox.files.search_files("/workspace", "*.py")
replacements = sandbox.files.replace_in_files(
    paths,
    "old_function",
    "new_function",
)
print(replacements)

Watch a directory

def on_event(event) -> None:
    print(event.type, event.event_type, event.path)

with sandbox.files.watch_dir("/workspace", on_event=on_event, recursive=True):
    sandbox.files.write("/workspace/changed.txt", "changed\n")
watch_dir calls on_event for file changes and returns a handle with stop(). recursive=True watches nested directories, and timeout= can bound how long the watch stays open. The CLI streams watch events as JSON lines.