Last Verified: 2025-01-27
Package:
hopx-ai on PyPI
Overview
TheFiles resource provides file operations for sandboxes. Access it via the files property on a Sandbox instance. All file operations are synchronous and work with both text and binary files.
The Files resource is lazy-loaded, meaning it’s only initialized when first accessed.
Access
Methods
read
Read text file contents.
path(str): File path to readtimeout(int, optional): Request timeout in seconds
str - File contents as string
Raises:
FileNotFoundError: File does not existFileOperationError: Read operation failed
read_bytes
Read binary file contents.
path(str): File path to readtimeout(int, optional): Request timeout
bytes - File contents as bytes
Example:
write
Write text file contents.
path(str): File path to writecontent(str): Text content to writemode(str, optional): File permissions (default:'0644')timeout(int, optional): Request timeout
FileOperationError: Write operation failed
write_bytes
Write binary file contents.
path(str): File path to writecontent(bytes): Binary content to writemode(str, optional): File permissionstimeout(int, optional): Request timeout
list
List directory contents.
path(str, optional): Directory path (default:'/workspace')timeout(int, optional): Request timeout
List[FileInfo] - List of file/directory information objects
Example:
exists
Check if file or directory exists.
path(str): File or directory pathtimeout(int, optional): Request timeout
bool - True if exists, False otherwise
Example:
remove
Delete file or directory.
path(str): File or directory path to deletetimeout(int, optional): Request timeout
FileNotFoundError: Path does not existFileOperationError: Delete operation failed
mkdir
Create directory.
path(str): Directory path to createtimeout(int, optional): Request timeout
FileOperationError: Directory creation failed
upload
Upload file from local filesystem to sandbox.
local_path(str): Local file pathremote_path(str): Remote file path in sandboxtimeout(int, optional): Request timeout
download
Download file from sandbox to local filesystem.
remote_path(str): Remote file path in sandboxlocal_path(str): Local file pathtimeout(int, optional): Request timeout
Examples
Example 1: Basic File Operations
Example 2: Working with Directories
Example 3: File Upload/Download
Example 4: Binary File Operations
FileInfo Model
Thelist() method returns FileInfo objects with the following properties:
name(str): File or directory namepath(str): Full pathsize(int): Size in bytesis_directory(bool): Whether it’s a directorypermissions(str): File permissionsmodified_time(datetime): Last modification timeis_file(bool): Convenience property (opposite ofis_directory)size_kb(float): Size in kilobytessize_mb(float): Size in megabytes
Related Classes
- Sandbox - Main sandbox class
- Commands - Command execution resource
- Models - Data models including
FileInfo
See Also
- Core Concepts: Files - Learn about file operations
- Sandbox Class - Access files via
sandbox.files
Related
- Reading Files - Learn about reading files
- Writing Files - Learn about writing files
- Listing Files - List directory contents
- API: File Operations - VM Agent API endpoints
Next Steps
- Learn about Reading Files to access file contents
- Explore Writing Files to create files
- Review Uploading Files for local file transfers
- CLI File Operations - Use file operations from the command line

