Overview
In addition to running commands, your AI agent may need to modify or read files on your Devbox. The Runloop Devbox provides full programmatic access to the underlying filesystem, allowing your agent to interact with files as needed.Writing Files to the Devbox
When authoring code, your AI Agent will often need to write files to disk. There are two main methods for this:Writing Small Text Files
You can usewrite_file_contents
to easily write a UTF-8 string to a file on disk. Note that all file paths are relative to the user’s home directory by default.
Uploading Large or Non-Text Files
For larger files or binary data, you should use theupload_file
API, which supports files of any sizes and allows passing non text data:
Reading Files
Your AI Agent will often also need to read files from the Devbox. There are two main methods for this:Reading Small Text Files
You can useread_file_contents
to read the contents of a file on the Devbox as a UTF-8 string.
Downloading Large or Non-Text Files
You can also usedownload_file
to download a file from the Devbox directly for large or non-text files.
Best Practices
-
Prefer to use
execute_async
wherever possible; timeouts forexecute_sync
are short and may not be enough for large files. - Always specify the full path when working with files to avoid ambiguity.
- Be mindful of file permissions when reading or writing files in different directories.
- Use error handling in your AI agent’s code to manage potential issues with file operations, such as “file not found” or “permission denied” errors.
- When working with files, prefer to use the asynchronous client if you’re working with Python to avoid timeouts.