Skip to main content

Overview

The SDK provides file operations for reading and writing both text and binary content inside sandboxes. All operations use absolute paths.

Size limits

  • Max write size: 10 MB per file (enforced by SDK)
  • For larger files, consider streaming from your app or hosting assets externally

Writing files

Text files

Binary files

Write binary data using ArrayBuffer or Uint8Array:

Reading files

Text files

Binary files

Common patterns

Upload and process

Generate and download

Multi-file operations

Implementation details

  • Files are transferred via base64 encoding over the exec API
  • Large files are chunked automatically (100KB chunks)
  • Absolute paths are required (e.g., /tmp/file.txt, not file.txt)
  • The SDK uses cat for reads and printf | base64 -d for writes

Error handling

Best practices

Always use absolute paths

File operations require absolute paths starting with /:

Specify encoding for binary files

Always use encoding: "binary" when working with non-text files:
Without the encoding parameter, binary files may be corrupted as the SDK defaults to UTF-8 text.

Other best practices

  • Check size limits: Ensure files are under 10 MB before writing
  • Batch operations: Use Promise.all() for multiple file operations
  • Handle errors: Wrap file operations in try-catch blocks
  • Clean up: Remove temporary files when done to save space