Skip to main content
Read the contents of files from the sandbox filesystem.
from gravixlayer import GravixLayer

client = GravixLayer(api_key="YOUR_API_KEY")

sandbox = client.sandbox.sandboxes.create(template="python-base-v1", timeout=300)
sid = sandbox.sandbox_id

# Write a file first
client.sandbox.sandboxes.write_file(sid, path="/home/user/test.txt", content="Hello World!")

# Read it back
result = client.sandbox.sandboxes.read_file(sid, path="/home/user/test.txt")
print(result.content)

Request Parameters

ParameterTypeRequiredDescription
pathstringYesAbsolute or relative path to the file

Response

{
  "content": "name,age\nAlice,25\nBob,30",
  "path": "/home/user/data.csv",
  "size": 23
}

Response Fields

FieldTypeDescription
contentstringFile contents as text
pathstringFull path to the file
sizeintegerFile size in bytes

Common File Paths

  • /home/user/ - User home directory
  • /home/user/output/ - Common output directory
  • /home/user/data/ - Common data directory
  • /tmp/ - Temporary files

Example: Read Configuration

result = client.sandbox.sandboxes.read_file(sid, path="/home/user/config.json")
print(result.content)

Example: Read Generated Output

result = client.sandbox.sandboxes.read_file(sid, path="/home/user/results.txt")
print(result.content)

Error Handling

File Not Found:
{
  "error": {
    "code": "file_not_found",
    "message": "File not found: /home/user/missing.txt"
  }
}
Permission Denied:
{
  "error": {
    "code": "permission_denied",
    "message": "Permission denied: /root/private.txt"
  }
}

Next Steps

Run Python Code

Create files with Python code

Run JavaScript Code

Create files with Node.js code

Run Commands

Create files with shell commands

Get Sandbox Info

Monitor sandbox status and resources