from hopx_ai import Sandbox
import os
API_KEY = os.getenv("HOPX_API_KEY")
with Sandbox.create(template="code-interpreter", api_key=API_KEY) as sandbox:
# Write text file
sandbox.files.write("/workspace/hello.txt", "Hello, World!")
print("File written: /workspace/hello.txt")
# Read file
content = sandbox.files.read("/workspace/hello.txt")
print(f"File content: {content}")
# Write binary file
binary_data = b"\x89PNG\r\n\x1a\n" # PNG header
sandbox.files.write_bytes("/workspace/test.png", binary_data)
print("Binary file written: /workspace/test.png")
# Read binary file
binary_content = sandbox.files.read_bytes("/workspace/test.png")
print(f"Binary content length: {len(binary_content)} bytes")