SandboxFileSystem¶
- class baseten.sandbox.SandboxFileSystem¶
Bases:
objectFiles and directories in a sandbox.
Relative paths are resolved against the sandbox’s working directory.
- Parameters:
context (SandboxContext)
process (SandboxProcess)
- copy(*, source, destination, timeout=datetime.timedelta(seconds=180))¶
Copy a file or directory.
Runs
cp -rin the sandbox throughSandboxProcess.exec(), then waits for it withSandboxProcess.wait(), socp’s rules apply, such as copying into a destination that is an existing directory.- Parameters:
- Raises:
SandboxFileSystemCopyError – The copy did not succeed.
SandboxProcessWaitTimeoutError – The copy was still running when the wait timed out.
- Return type:
None
- find(*, path, type=None, patterns=None, max_results=None, exclude_dirs=None, exclude_hidden=None)¶
Find files and directories by name under a directory.
- Parameters:
path (str) – Path of the directory to search in.
type (Literal['file', 'directory'] | str | None) – Whether to find only files or only directories.
Nonefinds both.patterns (list[str] | None) – File patterns to include, such as
"*.py".max_results (int | None) – Maximum number of results. 0 means all. The sandbox defaults to 20.
exclude_dirs (list[str] | None) – Directory names to skip. The sandbox defaults to common dependency and build directories, such as
node_modulesand.git.exclude_hidden (bool | None) – Whether to skip hidden files and directories. The sandbox defaults to true.
- Return type:
- grep(*, path, query, case_sensitive=None, max_results=None, file_pattern=None, exclude_dirs=None, context_lines=None)¶
Search the contents of files under a directory for text.
- Parameters:
path (str) – Path of the directory to search in.
query (str) – Text to search for.
case_sensitive (bool | None) – Whether the search is case sensitive. The sandbox defaults to false.
max_results (int | None) – Maximum number of results. The sandbox defaults to 100.
file_pattern (str | None) – File pattern to include, such as
"*.py".exclude_dirs (list[str] | None) – Directory names to skip. The sandbox defaults to common dependency and build directories, such as
node_modulesand.git.context_lines (int | None) – How many lines before and after each match to include in its
SandboxFileSystemGrepMatch.context, at most 20.Noneincludes none.
- Return type:
- list(*, path)¶
List a directory’s files and subdirectories, one level deep.
- Parameters:
path (str) – Path of the directory.
- Return type:
- mkdir(*, path, permissions=None)¶
Create a directory, along with any missing parents.
- read_bytes(*, path)¶
Read a file as bytes.
- remove(*, path, recursive=None)¶
Remove a file or directory.
- watch(*, path, recursive=None, ignore=None)¶
Stream changes in a directory as they happen.
Only the directory’s direct entries are watched unless recursive is set. Closing the stream stops watching.
- Parameters:
- Return type:
- write(*, path, content)¶
Write a text file, creating it or replacing its content.
Content over 5MB is uploaded in 5MB parts through the multipart upload endpoints, at most 2 parts at a time per sandbox.
- write_bytes(*, path, content, permissions=None)¶
Write a file from bytes, creating it or replacing its content.
Content over 5MB is uploaded in 5MB parts through the multipart upload endpoints, at most 2 parts at a time per sandbox.