Skip to content

Read & Write

Read files from a Sandbox using the files.read() method.

from agentbox import Sandbox

sandbox = Sandbox(
    api_key="ab_xxxxxxxxxxxxxxxxxxxxxxxxx",
    template="wemmodr8mb2uk3kn7exw",
    timeout=120)

file_content = sandbox.files.read('/path/to/file')

You can write single files to the sandbox filesystem using the files.write() method.

The write() method overwrites the file if it already exists.

from agentbox import Sandbox

sandbox = Sandbox(
    api_key="ab_xxxxxxxxxxxxxxxxxxxxxxxxx",
    template="wemmodr8mb2uk3kn7exw",
    timeout=120)

await sandbox.files.write('/path/to/file', 'file content')

You can also write multiple files to the sandbox filesystem using the files.write() method.

from agentbox import Sandbox

sandbox = Sandbox(
    api_key="ab_xxxxxxxxxxxxxxxxxxxxxxxxx",
    template="wemmodr8mb2uk3kn7exw",
    timeout=120)

sandbox.files.write([
    { "path": "/path/to/a", "data": "file content" },
    { "path": "another/path/to/b", "data": "file content" }
])