Read & Write
Reading files
Section titled “Reading files”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')
from agentbox import AsyncSandbox
sandbox = await AsyncSandbox.create(
api_key="ab_xxxxxxxxxxxxxxxxxxxxxxxxx",
template="wemmodr8mb2uk3kn7exw",
timeout=120)
file_content = await sandbox.files.read('/path/to/file')
Writing single file
Section titled “Writing single 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')
from agentbox import AsyncSandbox
sandbox = await AsyncSandbox.create(
api_key="ab_xxxxxxxxxxxxxxxxxxxxxxxxx",
template="wemmodr8mb2uk3kn7exw",
timeout=120)
await sandbox.files.write('/path/to/file', 'file content')
Writing multiple files
Section titled “Writing multiple files”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" }
])
from agentbox import AsyncSandbox
sandbox = await AsyncSandbox.create(
api_key="ab_xxxxxxxxxxxxxxxxxxxxxxxxx",
template="wemmodr8mb2uk3kn7exw",
timeout=120)
await sandbox.files.write([
{ "path": "/path/to/a", "data": "file content" },
{ "path": "another/path/to/b", "data": "file content" }
])