pub struct Workspace { /* private fields */ }Expand description
A workspace roots every file/search/shell operation at a directory and enforces a small capability policy.
All paths supplied to the tools are resolved relative to root
and rejected if they escape it. Mutating operations require
is_writable; bash requires bash_allowed.
The workspace also carries a small amount of shared session state — the set
of files that have been read — so that edit_file can require a prior
read_file (guarding against blind overwrites).
Workspace is cheap to clone; clones share the read-tracking state.
Implementations§
Source§impl Workspace
impl Workspace
Sourcepub fn new(root: impl Into<PathBuf>) -> Self
pub fn new(root: impl Into<PathBuf>) -> Self
Create a read-write workspace rooted at root (bash enabled).
If root exists it is canonicalized so containment checks are robust.
Sourcepub fn read_only(root: impl Into<PathBuf>) -> Self
pub fn read_only(root: impl Into<PathBuf>) -> Self
Create a read-only workspace (no writes, no bash) — useful for exploration / plan modes.
Sourcepub fn allow_bash(self, yes: bool) -> Self
pub fn allow_bash(self, yes: bool) -> Self
Set whether the bash tool is permitted.
Sourcepub fn bash_timeout(self, timeout: Duration) -> Self
pub fn bash_timeout(self, timeout: Duration) -> Self
Set the default timeout applied to bash commands.
Sourcepub fn max_output_bytes(self, bytes: usize) -> Self
pub fn max_output_bytes(self, bytes: usize) -> Self
Set the maximum number of bytes captured from a stream before truncation.
Sourcepub fn inherit_env(self, yes: bool) -> Self
pub fn inherit_env(self, yes: bool) -> Self
Pass the whole parent environment to bash.
Off by default, because the parent environment of an agent process routinely
holds provider API keys and a model-directed command can read them with env.
Enable it only when the commands you run genuinely need the caller’s environment
and you accept that exposure.
Sourcepub fn env_allowlist<I, S>(self, keys: I) -> Self
pub fn env_allowlist<I, S>(self, keys: I) -> Self
Replace the variables bash receives when the environment is not inherited.
Defaults to DEFAULT_ENV_ALLOWLIST. Adding a variable that holds a credential
re-exposes it.
Sourcepub fn inherits_env(&self) -> bool
pub fn inherits_env(&self) -> bool
Whether bash inherits the parent environment.
Sourcepub fn bash_env(&self) -> Vec<(String, String)>
pub fn bash_env(&self) -> Vec<(String, String)>
The variables bash receives, resolved from the current process.
Empty when the environment is inherited, in which case the caller must not clear it.
Sourcepub fn is_writable(&self) -> bool
pub fn is_writable(&self) -> bool
Whether mutating file operations are permitted.
Sourcepub fn bash_allowed(&self) -> bool
pub fn bash_allowed(&self) -> bool
Whether the bash tool is permitted.
Sourcepub fn bash_timeout_value(&self) -> Duration
pub fn bash_timeout_value(&self) -> Duration
The default bash timeout.
Sourcepub fn max_output(&self) -> usize
pub fn max_output(&self) -> usize
The output-capture cap.