Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add container filesystem API for sandboxes #2414

Open
wants to merge 41 commits into
base: main
Choose a base branch
from
Open

Conversation

azliu0
Copy link
Contributor

@azliu0 azliu0 commented Oct 27, 2024

Describe your changes

Resolves WRK-414 by adding a new container filesystem API.

This API is designed to closely follow io.FileIO, supporting most of the major functions (open, read, readline, readlines, write, seek, flush, close) along with a few higher-level functions (delete_bytes, write_replace_bytes) to help make Sandboxes a bit easier to use.

All file modes (e.g. text, bytes, r/w/a/x, etc.) are supported, as well as most common errors/exceptions. If an unknown exception is thrown, then a modal.exception.FilesystemExecutionError is thrown instead.

Example usage:

app = modal.App.lookup("sandbox-fs", create_if_missing=True)
sb = modal.Sandbox.create(app=app)

with sb.open("test.txt", "w") as f:
  f.write("Hello World\n")

f = sb.open("test.txt", "rb")
print(f.read())
Backward/forward compatibility checks

Check these boxes or delete any item (or this section) if not relevant for this PR.

  • Client+Server: this change is compatible with old servers
  • Client forward compatibility: this change ensures client can accept data intended for later versions of itself

Note on protobuf: protobuf message changes in one place may have impact to
multiple entities (client, server, worker, database). See points above.


Changelog

Sandboxes now support a new filesystem API. The open() method returns a FileIO handle for native file handling in sandboxes.

app = modal.App.lookup("sandbox-fs", create_if_missing=True)
sb = modal.Sandbox.create(app=app)

with sb.open("test.txt", "w") as f:
  f.write("Hello World\n")

f = sb.open("test.txt", "rb")
print(f.read())

@azliu0 azliu0 requested a review from pawalt October 28, 2024 12:27
@azliu0 azliu0 changed the title Add container filesystem for sandboxes Add container filesystem API for sandboxes Oct 28, 2024
@pawalt
Copy link
Member

pawalt commented Oct 28, 2024

@azliu0 can you convert this to draft until we have worker & server support? Also this will need to be tested somehow. Need to mock the underlying RPCs.

@azliu0 azliu0 marked this pull request as draft October 28, 2024 14:06
Base automatically changed from azliu/sandbox-fs-proto to main October 28, 2024 14:36
@azliu0 azliu0 marked this pull request as ready for review October 29, 2024 21:49
@azliu0 azliu0 requested a review from mwaskom October 29, 2024 21:52
@mwaskom
Copy link
Contributor

mwaskom commented Oct 30, 2024

Can we improve the changelog a bit here?

modal/file_io.py Outdated Show resolved Hide resolved
modal/file_io.py Show resolved Hide resolved
modal/file_io.py Show resolved Hide resolved
modal/file_io.py Show resolved Hide resolved
modal/sandbox.py Show resolved Hide resolved
@azliu0 azliu0 requested a review from pawalt October 31, 2024 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants