class BaseWorkspace
Bases:DiscriminatedUnionMixin, ABC
Abstract base class for workspace implementations.
Workspaces provide a sandboxed environment where agents can execute commands,
read/write files, and perform other operations. All workspace implementations
support the context manager protocol for safe resource management.
Properties
working_dir: Annotated[str, BeforeValidator(_convert_path_to_str), Field(description=‘The working directory for agent operations and tool execution. Accepts both string paths and Path objects. Path objects are automatically converted to strings.’)]
Methods
abstractmethod execute_command() -> CommandResult source Execute a bash command on the system. Parameters:commandstr – The bash command to executecwdstr | Path | None – Working directory for the command (optional)timeoutfloat – Timeout in seconds (defaults to 30.0)
- CommandResult Result containing stdout, stderr, exit_code, and other metadata
-
Exception– If command execution failsNoneNoneNone
source_pathstr | Path – Path to the source filedestination_pathstr | Path – Path where the file should be uploaded
- FileOperationResult Result containing success status and metadata
-
Exception– If file upload failsNoneNone
source_pathstr | Path – Path to the source file on the systemdestination_pathstr | Path – Path where the file should be downloaded
- FileOperationResult Result containing success status and metadata
-
Exception– If file download failsNoneNone
pathstr | Path – Path to the git repository
- list[GitChange] list[GitChange]: List of changes
-
Exception– If path is not a git repository or getting changes failedNone
pathstr | Path – Path to the file
- GitDiff Git diff
-
Exception– If path is not a git repository or getting diff failedNone
NotImplementedError– If the workspace type does not support pausing.
NotImplementedError– If the workspace type does not support resuming.
class LocalWorkspace
Bases:BaseWorkspace
Local workspace implementation that operates on the host filesystem.
LocalWorkspace provides direct access to the local filesystem and command execution
environment. It’s suitable for development and testing scenarios where the agent
should operate directly on the host system.
Methods
init() sourceNone
None
commandstr – The bash command to executecwdstr | Path | None – Working directory (optional)timeoutfloat – Timeout in seconds
-
CommandResult Result with stdout, stderr, exit_code, command, and
timeout_occurred
NoneNoneNone
source_pathstr | Path – Path to the source filedestination_pathstr | Path – Path where the file should be copied
-
FileOperationResult Result with success status and file information
NoneNone
source_pathstr | Path – Path to the source filedestination_pathstr | Path – Path where the file should be copied
-
FileOperationResult Result with success status and file information
NoneNone
pathstr | Path – Path to the git repository
- list[GitChange] list[GitChange]: List of changes
-
Exception– If path is not a git repository or getting changes failedNone
pathstr | Path – Path to the file
- GitDiff Git diff
-
Exception– If path is not a git repository or getting diff failedNone
class CommandResult
Bases:BaseModel
Result of executing a command in the workspace.
Properties
command: str The command that was executedexit_code: int Exit code of the commandstdout: str Standard output from the commandstderr: str Standard error from the commandtimeout_occurred: bool Whether the command timed out during execution
class FileOperationResult
Bases:BaseModel
Result of a file upload or download operation.
Properties
success: bool Whether the operation was successfulsource_path: str Path to the source filedestination_path: str Path to the destination filefile_size: int | None Size of the file in bytes (if successful)error: str | None Error message (if operation failed)
class RemoteWorkspace
Bases:RemoteWorkspaceMixin, BaseWorkspace
Remote workspace implementation that connects to an OpenHands agent server.
RemoteWorkspace provides access to a sandboxed environment running on a remote
OpenHands agent server. This is the recommended approach for production deployments
as it provides better isolation and security.
Properties
client: httpx.Clientalive: bool Check if the remote workspace is alive by querying the health endpoint.
Methods
reset_client() -> None source Reset the HTTP client to force re-initialization. This is useful when connection parameters (host, api_key) have changed and the client needs to be recreated with new values. execute_command() -> CommandResult source Execute a bash command on the remote system. This method starts a bash command via the remote agent server API, then polls for the output until the command completes. Parameters:commandstr – The bash command to executecwdstr | Path | None – Working directory (optional)timeoutfloat – Timeout in seconds
-
CommandResult Result with stdout, stderr, exit_code, and other metadata
NoneNoneNone
source_pathstr | Path – Path to the local source filedestination_pathstr | Path – Path where the file should be uploaded on remote system
-
FileOperationResult Result with success status and metadata
NoneNone
source_pathstr | Path – Path to the source file on remote systemdestination_pathstr | Path – Path where the file should be saved locally
-
FileOperationResult Result with success status and metadata
NoneNone
pathstr | Path – Path to the git repository
- list[GitChange] list[GitChange]: List of changes
-
Exception– If path is not a git repository or getting changes failedNone
pathstr | Path – Path to the file
- GitDiff Git diff
-
Exception– If path is not a git repository or getting diff failedNone

