Skip to main content
Manage files and directories in GravixLayer sandboxes with comprehensive file system operations including read, write, upload, download, and directory management.

Basic File Operations

Writing Files

# Write text content to file
gravixlayer sandbox file write <sandbox_id> "/home/user/hello.txt" "Hello World!"

# Write JSON data to file
gravixlayer sandbox file write <sandbox_id> "/home/user/data.json" '{"name": "Alice", "age": 30}'

# Write multiline content
gravixlayer sandbox file write <sandbox_id> "/home/user/config.txt" "line1\nline2\nline3"
Expected Outcome
Text file written successfully
JSON file written successfully

Reading Files

# First create a file to read
gravixlayer sandbox file write <sandbox_id> "/home/user/sample.txt" "Hello World!"

# Read the file content
gravixlayer sandbox file read <sandbox_id> "/home/user/sample.txt"

# Read JSON file
gravixlayer sandbox file write <sandbox_id> "/home/user/config.json" '{"debug": true, "port": 8080}'
gravixlayer sandbox file read <sandbox_id> "/home/user/config.json"
Expected Outcome
File content:
FileReadResponse(content='Hello World!\nThis is line 2.', path=None, size=None)
JSON data: {'debug': True, 'port': 8080}

Listing Files

# Create some files first
gravixlayer sandbox file write <sandbox_id> "/home/user/file1.txt" "Content 1"
gravixlayer sandbox file write <sandbox_id> "/home/user/file2.txt" "Content 2"
gravixlayer sandbox file write <sandbox_id> "/home/user/data.json" '{"key": "value"}'

# List files with details
gravixlayer sandbox run <sandbox_id> ls --args="-la" --args="/home/sandbox"

# List only file names
gravixlayer sandbox run <sandbox_id> ls --args="/home/sandbox"

# List files with specific pattern
gravixlayer sandbox run <sandbox_id> ls --args="/home/sandbox/*.txt"
Expected Outcome
Detailed listing:
total 12
drwxr-xr-x 2 user user 4096 Jan 27 10:30 .
drwxr-xr-x 3 root root 4096 Jan 27 10:30 ..
-rw-r--r-- 1 user user   15 Jan 27 10:30 data.json
-rw-r--r-- 1 user user    9 Jan 27 10:30 file1.txt
-rw-r--r-- 1 user user    9 Jan 27 10:30 file2.txt
File names:
data.json  file1.txt  file2.txt

Deleting Files

# Create files to delete
gravixlayer sandbox file write <sandbox_id> "/home/user/temp.txt" "Temporary content"
gravixlayer sandbox file write <sandbox_id> "/home/user/delete_me.json" '{"temp": true}'

# Delete single file
gravixlayer sandbox run <sandbox_id> rm --args="/home/sandbox/temp.txt"

# Delete multiple files
gravixlayer sandbox run <sandbox_id> rm --args="/home/sandbox/delete_me.json"

# Verify deletion
gravixlayer sandbox run <sandbox_id> ls --args="/home/sandbox"

# Delete with pattern (be careful!)
gravixlayer sandbox file write <sandbox_id> "/home/sandbox/temp1.log" "log1"
gravixlayer sandbox file write <sandbox_id> "/home/sandbox/temp2.log" "log2"
gravixlayer sandbox run <sandbox_id> rm --args="/home/sandbox/*.log"
Expected Outcome:
Files before deletion:
delete_me.json  temp.txt
Files deleted successfully
Files after deletion:
(empty or remaining files)

Directory Management

Creating Directories

# Create single directory
gravixlayer sandbox run <sandbox_id> mkdir --args="/home/sandbox/project"

# Create nested directories
gravixlayer sandbox run <sandbox_id> mkdir --args="-p" --args="/home/sandbox/data/raw/csv"

# Create multiple directories
gravixlayer sandbox run <sandbox_id> mkdir --args="/home/sandbox/logs" --args="/home/sandbox/temp" --args="/home/sandbox/output"

# Verify directory creation
gravixlayer sandbox run <sandbox_id> ls --args="-la" --args="/home/sandbox"
gravixlayer sandbox run <sandbox_id> find --args="/home/sandbox" --args="-type" --args="d"
Expected output
Directories created successfully
Created directories:
/home/user
/home/user/data
/home/user/data/raw
/home/user/data/raw/csv
/home/user/logs
/home/user/output
/home/user/project
/home/user/temp

File Upload and Download

Upload Local Files

# Upload a single file
gravixlayer sandbox file upload <sandbox_id> "./local_file.txt" "/home/user/uploaded.txt"

# Upload with different name
gravixlayer sandbox file upload <sandbox_id> "./data.csv" "/home/user/dataset.csv"

# Upload to specific directory
gravixlayer sandbox file upload <sandbox_id> "./config.json" "/home/user/config/app.json"

# Verify upload
gravixlayer sandbox file read <sandbox_id> "/home/user/uploaded.txt"
Expected output
File uploaded successfully
Uploaded content:
This is content from a local file.
Line 2
Line 3
Files in sandbox:
total 4
drwxr-xr-x 2 user user 4096 Jan 27 10:30 .
drwxr-xr-x 3 root root 4096 Jan 27 10:30 ..
-rw-r--r-- 1 user user   45 Jan 27 10:30 uploaded.txt

Download Files from Sandbox

# Create a file in sandbox first
gravixlayer sandbox file write <sandbox_id> "/home/user/download_me.txt" "This file will be downloaded.\nWith multiple lines."

# Download file from sandbox to local system
gravixlayer sandbox file download <sandbox_id> "/home/user/download_me.txt" "./downloaded_file.txt"

# Download generated file (e.g., from data processing)
gravixlayer sandbox file write <sandbox_id> "/home/user/result.csv" "name,age,city\nAlice,25,NYC\nBob,30,LA"
gravixlayer sandbox file download <sandbox_id> "/home/user/result.csv" "./output.csv"

# Download to different local path
gravixlayer sandbox file download <sandbox_id> "/home/user/result.csv" "./data/processed_data.csv"

# Verify local file
cat ./downloaded_file.txt
Expected output
Downloaded text file (58 characters)
Downloaded CSV file (55 characters)
Local text file content:
This file will be downloaded.
With multiple lines.
Generated in sandbox.
Local CSV content:
name,age,city
Alice,25,NYC
Bob,30,LA
Charlie,35,Chicago

Next Steps