Skip to main content
Transfer files between your local machine and sandboxes, or manage files directly inside the sandbox filesystem.
File operations use the sandbox proxy URL: https://<sandbox-id>.sandbox.tensorlake.ai

Copy Files

from tensorlake.sandbox import SandboxClient

client = SandboxClient()
sandbox = client.create_and_connect()

# Write a file into the sandbox
sandbox.write_file("/workspace/data.csv", b"name,score\nAlice,95\nBob,87")

# Read a file from the sandbox
content = sandbox.read_file("/workspace/data.csv")
print(bytes(content).decode("utf-8"))

Read Files

# Read text content
content = sandbox.read_file("/workspace/data.csv")
print(bytes(content).decode("utf-8"))

# Read binary content (e.g., images, archives)
image_bytes = sandbox.read_file("/workspace/chart.png")
with open("chart.png", "wb") as f:
    f.write(image_bytes)

Write Files

# Write text content
sandbox.write_file("/workspace/config.json", b'{"debug": true, "port": 8080}')

# Write binary content
with open("model.pkl", "rb") as f:
    sandbox.write_file("/workspace/model.pkl", f.read())

List Directory Contents

entries = sandbox.list_directory("/workspace")
for entry in entries.entries:
    print(f"{entry.name} ({entry.size} bytes)")

Delete Files

sandbox.run("rm", ["-rf", "/workspace/temp"])

Organize Files

# Create directories
sandbox.run("mkdir", ["-p", "/workspace/src/components"])

# Move files
sandbox.run("mv", ["/workspace/old.txt", "/workspace/new.txt"])

Best Practices

  • Use /workspace as the default directory for application files.
  • Use absolute paths to avoid ambiguity.
  • For large transfers, copy a directory rather than individual files.
  • Use write_file / read_file (Python) for programmatic access. Use tl sbx cp (CLI) for bulk file transfers.

Learn More