List Directories
Updated at:
Listing directories helps you inspect the file structure inside the sandbox. It is useful when an agent needs to explore a working directory, check generated outputs, or locate logs.
List directory contents
Python example:
entries = sandbox.files.list("/tmp")
for entry in entries:
print(entry.name, entry.type, entry.path)TypeScript example:
const entries = await sandbox.files.list("/tmp");
for (const entry of entries) {
console.log(entry.name, entry.type, entry.path);
}Use with command execution
Python example:
sandbox.commands.run("mkdir -p /tmp/project && touch /tmp/project/app.py")
files = sandbox.files.list("/tmp/project")
print([file.name for file in files])TypeScript example:
await sandbox.commands.run("mkdir -p /tmp/project && touch /tmp/project/app.py");
const files = await sandbox.files.list("/tmp/project");
console.log(files.map((file) => file.name));Recommendations
Directories may contain many files. If your application needs to render a directory tree, expand paths on demand instead of recursively reading a large number of paths in a single request.
Is this page helpful?