Skip to content

Add SandboxFileSystem.create_file#1698

Open
RitwijParmar wants to merge 1 commit into
beam-cloud:mainfrom
RitwijParmar:codex/sandbox-create-file
Open

Add SandboxFileSystem.create_file#1698
RitwijParmar wants to merge 1 commit into
beam-cloud:mainfrom
RitwijParmar:codex/sandbox-create-file

Conversation

@RitwijParmar

@RitwijParmar RitwijParmar commented Jun 17, 2026

Copy link
Copy Markdown

Summary

Fixes #1520.

Adds SandboxFileSystem.create_file() for creating sandbox files directly from in-memory text or bytes. This uses the existing sandbox upload RPC instead of shelling out in the sandbox.

The helper keeps writes explicit and safe:

  • normalizes POSIX sandbox paths
  • accepts str and bytes contents
  • supports file modes
  • optionally creates missing parent directories
  • refuses to overwrite existing files unless overwrite=True
  • exposes the same helper through instance.fs.aio.create_file()

Checks

  • sdk/.venv/bin/python -m pytest sdk/tests/test_sandbox_filesystem.py -q
  • sdk/.venv/bin/python -m ruff check sdk/src/beta9/abstractions/sandbox.py sdk/tests/test_sandbox_filesystem.py
  • python3 -m compileall -q sdk/src/beta9/abstractions/sandbox.py sdk/tests/test_sandbox_filesystem.py
  • git diff --check

Note: I initially tried uv run with the default interpreter, but local uv selected Python 3.14 and pydantic-core in this repo does not build against that PyO3 version. I reran the checks with Python 3.11, which is inside the package support range.


Summary by cubic

Add SandboxFileSystem.create_file() to write files in the sandbox from in-memory text or bytes using the upload RPC. Also adds fs.aio.create_file() and avoids shelling out for simple writes.

  • New Features
    • New SandboxFileSystem.create_file() (and fs.aio.create_file()) creates files from str/bytes with optional encoding and file mode.
    • Safer writes: normalizes POSIX paths, can create missing parents (parents=True), and refuses to overwrite unless overwrite=True.
    • Clear errors: FileExistsError for existing files without overwrite; SandboxFileSystemError for RPC failures; validates paths and contents.
    • Tests added for strings/bytes, parent creation order, overwrite rules, and async delegation.

Written for commit 372fb24. Summary will update on new commits.

Review in cubic

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.

add sandbox.create_file() method

1 participant