01Documentation
Files
Read and manage persistent files without starting or resuming sandbox compute. The existing Files API and SDK methods support reading, writing, listing, stat, directory creation, moving, and deletion while a sandbox is paused.
Files belong to the sandbox identity and survive successful checkpointed pause/resume. Deleting the sandbox removes its current filesystem; create a snapshot or fork first when you need a reusable copy.
Access While Paused#
No new endpoint, flag, or SDK is required. Offline access uses platform storage workers and storage services while the sandbox's guest compute remains stopped; it does not execute guest commands. File operations do not trigger auto_resume, including when it is enabled, and work when auto_resume is disabled.
| Sandbox state | File operations |
|---|---|
| Running | Read and modify the current guest filesystem. |
| Filesystem-only pause | Read, write, stat, list, mkdir, move, and delete persistent files without resuming compute. Successful changes are durable and visible on the next resume. |
| Memory pause | Read, stat, and list the committed RootFS without resuming. Writes, mkdir, move, and delete return 409 conflict to preserve the retained process state. |
| Lifecycle transition | Requests can wait for the current operation or return a conflict/unavailable response. They never start compute to work around a conflict. |
To edit files while preserving a memory checkpoint's processes, explicitly resume with memory first. File access never silently drops a memory checkpoint or switches to a fresh process launch.
Offline access covers the persistent RootFS. Virtual filesystems and runtime mounts, such as /tmp, /proc, /sys, /dev, managed credentials, and template tmpfs mounts, require the runtime and are unavailable offline. Offline operations reject these paths, including aliases through symlinks; directories containing runtime mounts cannot be moved or deleted offline. SSH/SFTP and file watching also require running compute; watch keeps its existing auto_resume behavior.
Use a handle for an existing sandbox; creating the handle does not claim or resume compute:
gosandbox := client.Sandbox("sb_abc123") entries, err := sandbox.ListFiles(ctx, "/workspace") if err != nil { log.Fatal(err) } content, err := sandbox.ReadFile(ctx, "/workspace/output.txt") if err != nil { log.Fatal(err) } // During a filesystem-only pause, this persists without resuming compute. _, err = sandbox.WriteFile(ctx, "/workspace/input.txt", []byte("next task")) if err != nil { log.Fatal(err) } fmt.Printf("Listed %d entries; read %d bytes\n", len(entries), len(content))
Offline writes publish a new immutable filesystem generation before returning success. They serialize with resume, restore, snapshots, deletion, and other writes. A failed operation does not publish its partial changes. If a connection is lost, the mutation outcome may be uncertain: inspect the file or directory before retrying a move, delete, or write. A write replaces one file atomically; several API calls are separate operations.
File Model#
FileInfo#
| Field | Type | Description |
|---|---|---|
name | string | File name |
path | string | Requested path, or a directory entry path beneath it; use absolute paths for unambiguous results |
type | string | File type: file, dir, symlink |
size | integer | File size in bytes |
mode | string | Unix file mode (e.g., 0755) |
mod_time | string | Last modification time (ISO 8601) |
is_link | boolean | Whether it's a symlink |
link_target | string | Symlink target path (if applicable) |
Write File#
Write content to a file. Creates the file and missing parent directories if needed, or atomically replaces the existing file. Each call writes the complete new content; it does not append.
/api/v1/sandboxes/{id}/files
Query Parameters#
| Parameter | Type | Description |
|---|---|---|
path | string | File path to write (required) |
Request Body#
Binary file content (raw bytes), up to 100 MiB. The limit is the same for running and paused sandboxes.
go// Write file content content := []byte("Hello from Sandbox0!\n") _, err := sandbox.WriteFile(ctx, "/workspace/hello.txt", content) if err != nil { log.Fatal(err) } fmt.Println("File written successfully")
Read File#
Read file content from a sandbox.
/api/v1/sandboxes/{id}/files
Query Parameters#
| Parameter | Type | Description |
|---|---|---|
path | string | File path to read (required) |
go// Read the file readResult, err := sandbox.ReadFile(ctx, "/workspace/hello.txt") if err != nil { log.Fatal(err) } fmt.Printf("File content: %s\n", strings.TrimSpace(string(readResult)))
Create Directory#
Create a new directory.
/api/v1/sandboxes/{id}/files
Query Parameters#
| Parameter | Type | Description |
|---|---|---|
path | string | Directory path to create (required) |
mkdir | boolean | Set to true to create directory |
recursive | boolean | Create parent directories if needed |
go// Create directory (with parent directories) _, err = sandbox.Mkdir(ctx, "/workspace/project/src", true) if err != nil { log.Fatal(err) } fmt.Println("Directory created")
Move File or Directory#
Move or rename a file or directory.
/api/v1/sandboxes/{id}/files/move
Request Body#
| Field | Type | Description |
|---|---|---|
source | string | Source path |
destination | string | Destination path |
go// Move/rename file _, err = sandbox.MoveFile(ctx, "/workspace/hello.txt", "/workspace/new-hello.txt") if err != nil { log.Fatal(err) } fmt.Println("File moved")
Delete File or Directory#
Delete a file or directory.
/api/v1/sandboxes/{id}/files
Query Parameters#
| Parameter | Type | Description |
|---|---|---|
path | string | Path to delete (required) |
Deleting a directory removes all its contents recursively. This action cannot be undone.
go// Delete file _, err = sandbox.DeleteFile(ctx, "/workspace/new-hello.txt") if err != nil { log.Fatal(err) } fmt.Println("File deleted")
Get File Info (Stat)#
Get metadata about a file or directory.
/api/v1/sandboxes/{id}/files/stat
Query Parameters#
| Parameter | Type | Description |
|---|---|---|
path | string | File path to stat (required) |
go// Recreate the sample file after the earlier move/delete examples. if _, err := sandbox.WriteFile(ctx, "/workspace/hello.txt", []byte("Hello from Sandbox0!\n")); err != nil { log.Fatal(err) } // Get file info info, err := sandbox.StatFile(ctx, "/workspace/hello.txt") if err != nil { log.Fatal(err) } if name, ok := info.Name.Get(); ok { fmt.Printf("Name: %s\n", name) } if size, ok := info.Size.Get(); ok { fmt.Printf("Size: %d bytes\n", size) } if fileType, ok := info.Type.Get(); ok { fmt.Printf("Type: %s\n", fileType) } if mode, ok := info.Mode.Get(); ok { fmt.Printf("Mode: %s\n", mode) }
List Directory#
List contents of a directory.
/api/v1/sandboxes/{id}/files/list
Query Parameters#
| Parameter | Type | Description |
|---|---|---|
path | string | Directory path to list (required) |
go// List directory contents entries, err := sandbox.ListFiles(ctx, "/workspace") if err != nil { log.Fatal(err) } for _, entry := range entries { path, ok := entry.Path.Get() if !ok { continue } fileType, _ := entry.Type.Get() size, _ := entry.Size.Get() fmt.Printf("- %s (%s, %d bytes)\n", path, fileType, size) }
Watch Files#
Watch a directory for file system changes in real-time via WebSocket. Watching requires a running sandbox and can resume compute when auto_resume is enabled. Offline reads and edits do not provide a watch stream.
/api/v1/sandboxes/{id}/files/watch
WebSocket Protocol#
Client Messages:
| Action | Description | Example |
|---|---|---|
subscribe | Subscribe to a path | {"action": "subscribe", "path": "/tmp", "recursive": true} |
unsubscribe | Unsubscribe from a watch | {"action": "unsubscribe", "watch_id": "watch-123"} |
Server Messages:
| Type | Description | Example |
|---|---|---|
subscribed | Subscription confirmed | {"type": "subscribed", "watch_id": "watch-123", "path": "/tmp"} |
event | File event occurred | {"type": "event", "watch_id": "watch-123", "event": "write", "path": "/tmp/a.txt"} |
unsubscribed | Unsubscription confirmed | {"type": "unsubscribed", "watch_id": "watch-123"} |
error | Error occurred | {"type": "error", "error": "permission denied"} |
File Events#
| Event | Description |
|---|---|
create | File or directory created |
write | File content modified |
rename | File or directory renamed |
chmod | File permissions changed |
remove | File or directory deleted |
go// Watch files for changes watchCtx, cancel := context.WithTimeout(ctx, 30*time.Second) defer cancel() events, errs, unsubscribe, err := sandbox.WatchFiles(watchCtx, "/workspace", true) if err != nil { log.Fatal(err) } defer func() { if err := unsubscribe(); err != nil { log.Printf("cleanup unsubscribe watch: %v", err) } }() // Process events for { select { case ev, ok := <-events: if !ok { return } fmt.Printf("Event: %s on %s\n", ev.Event, ev.Path) case err, ok := <-errs: if !ok { errs = nil continue } if err != nil { log.Printf("Watch error: %v", err) } case <-watchCtx.Done(): fmt.Println("Watch timeout") return } }