Typical flow
Methods
The accessor is obtained from a running sandbox viasb.FS(). Every method takes a context.Context first and returns an error (wrapped, inspectable with m.IsKind).
fs.Read()
Example
Example
BufferTooSmall on the single-shot path, and this method transparently falls back to ReadStream. Callers get a uniform bytes-returning interface up to runtime memory limits.
Parameters
ctxcontext.ContextCancels the read.
pathstringAbsolute path inside the guest, e.g.
“/app/config.json”.Returns
[]byte
File contents.
fs.ReadString()
Example
Example
Parameters
ctxcontext.ContextCancels the read.
pathstringAbsolute path inside the guest.
Returns
string
File contents.
fs.Write()
Example
Example
Parameters
ctxcontext.ContextCancels the write.
pathstringAbsolute path inside the guest.
data[]byteBytes to write.
fs.WriteString()
Example
Example
Write.
Parameters
ctxcontext.ContextCancels the write.
pathstringAbsolute path inside the guest.
contentstringText to write.
fs.List()
Example
Example
Parameters
ctxcontext.ContextCancels the listing.
pathstringAbsolute directory path inside the guest.
Returns
Directory entries.
fs.Stat()
Example
Example
Parameters
ctxcontext.ContextCancels the stat.
pathstringAbsolute path inside the guest.
Returns
File metadata.
fs.Mkdir()
Example
Example
Parameters
ctxcontext.ContextCancels the operation.
pathstringAbsolute directory path inside the guest.
fs.Remove()
Example
Example
RemoveDir for directories.
Parameters
ctxcontext.ContextCancels the operation.
pathstringAbsolute file path inside the guest.
fs.RemoveDir()
Example
Example
Parameters
ctxcontext.ContextCancels the operation.
pathstringAbsolute directory path inside the guest.
fs.Copy()
Example
Example
Parameters
ctxcontext.ContextCancels the operation.
srcstringSource path inside the guest.
dststringDestination path inside the guest.
fs.Rename()
Example
Example
Parameters
ctxcontext.ContextCancels the operation.
srcstringCurrent path inside the guest.
dststringNew path inside the guest.
fs.Exists()
Example
Example
Parameters
ctxcontext.ContextCancels the check.
pathstringAbsolute path inside the guest.
Returns
bool
true if the path exists.fs.CopyFromHost()
Example
Example
Parameters
ctxcontext.ContextCancels the copy.
hostPathstringSource path on the host.
guestPathstringDestination path inside the guest.
fs.CopyToHost()
Example
Example
Parameters
ctxcontext.ContextCancels the copy.
guestPathstringSource path inside the guest.
hostPathstringDestination path on the host.
fs.ReadStream()
Example
Example
Close the returned *FsReadStream. Read falls back to this automatically when a file exceeds the single-shot buffer.
Parameters
ctxcontext.ContextCancels opening the stream.
pathstringAbsolute path inside the guest.
Returns
Open read stream; close it when done.
fs.WriteStream()
Example
Example
Close(ctx) on the returned *FsWriteStream to finalise the write.
Parameters
ctxcontext.ContextCancels opening the stream.
pathstringAbsolute path inside the guest.
Returns
Open write stream;
Close(ctx) it to finalise.Types
FsEntry
Returned by List()
A single directory listing entry.| Field | Type | Description |
|---|---|---|
| Path | string | File path |
| Kind | FsEntryKind | Entry type |
| Size | int64 | File size in bytes |
| Mode | uint32 | Unix permission bits |
FsEntryKind
Used by FsEntry.Kind
Classifies a directory listing entry. Defined astype FsEntryKind string.
| Constant | Value | Description |
|---|---|---|
FsEntryKindFile | "file" | Regular file |
FsEntryKindDirectory | "directory" | Directory |
FsEntryKindSymlink | "symlink" | Symbolic link |
FsEntryKindOther | "other" | Other entry type |
FsStat
Returned by Stat()
Detailed file metadata.| Field | Type | Description |
|---|---|---|
| Path | string | File path |
| Size | int64 | File size in bytes |
| Mode | uint32 | Unix permission bits |
| ModTime | time.Time | Last modified timestamp; zero value if the guest did not report one |
| IsDir | bool | Whether the path is a directory |
FsReadStream
Returned by ReadStream()
An open streaming read from a guest file. Must be closed withClose when done.
| Method | Returns | Description |
|---|---|---|
Recv(ctx context.Context) | ([]byte, error) | Receive the next chunk; returns (nil, nil) at EOF |
WriteTo(w io.Writer) | (int64, error) | Drain the stream into w using context.Background(); implements io.WriterTo |
CopyTo(ctx context.Context, w io.Writer) | (int64, error) | Drain into w honouring ctx for per-chunk cancellation |
Close() | error | Release the read stream handle |
WriteTo and CopyTo return the partial byte count and leave the stream open so the caller can recover; close it explicitly in either case.
FsWriteStream
Returned by WriteStream()
An open streaming write to a guest file. Must be closed withClose(ctx) to finalise the write.
| Method | Returns | Description |
|---|---|---|
Write(p []byte) | (int, error) | Send a chunk; implements io.Writer, uses context.Background() internally |
WriteCtx(ctx context.Context, data []byte) | error | Send a chunk with explicit context control |
Close(ctx context.Context) | error | Send the EOF marker and wait for the guest to confirm; must be called to complete the write |