Skip to main content
The Workspace component abstracts execution environments for agent operations. It provides a unified interface for command execution and file operations across local processes, containers, and remote servers. Source: openhands/sdk/workspace/

Core Responsibilities

The Workspace system has four primary responsibilities:
  1. Execution Abstraction - Unified interface for command execution across environments
  2. File Operations - Upload, download, and manipulate files in workspace
  3. Resource Management - Context manager protocol for setup/teardown
  4. Environment Isolation - Separate agent execution from host system

Architecture

Key Components

ComponentPurposeDesign
BaseWorkspaceAbstract interfaceDefines execution and file operation contracts
LocalWorkspaceLocal executionSubprocess-based command execution
RemoteWorkspaceRemote executionHTTP API-based execution via agent-server
CommandResultExecution outputStructured result with stdout, stderr, exit_code
FileOperationResultFile op outcomeSuccess status and metadata

Workspace Types

Local vs Remote Execution

AspectLocalWorkspaceRemoteWorkspace
ExecutionDirect subprocessHTTP → agent-server
IsolationProcess-levelContainer/VM-level
PerformanceFast (no network)Network overhead
SecurityHost system accessSandboxed
Use CaseDevelopment, CLIProduction, web apps

Core Operations

Command Execution

Command Result Structure:
FieldTypeDescription
stdoutstrStandard output stream
stderrstrStandard error stream
exit_codeintProcess exit code (0 = success)
timeoutboolWhether command timed out
durationfloatExecution time in seconds

File Operations

OperationLocal ImplementationRemote Implementation
Uploadshutil.copy()POST /file/upload with multipart
Downloadshutil.copy()GET /file/download stream
ResultFileOperationResultFileOperationResult

Resource Management

Workspaces use context manager for safe resource handling: Lifecycle Hooks:
PhaseLocalWorkspaceRemoteWorkspace
EnterCreate working directoryConnect to agent-server, verify
UseExecute commandsProxy commands via HTTP
ExitNo cleanup (persistent)Disconnect, optionally stop container

Remote Workspace Extensions

The SDK provides remote workspace implementations in openhands-workspace package: Implementation Comparison:
TypeSetupIsolationUse Case
LocalWorkspaceImmediateProcessDevelopment, trusted code
DockerWorkspaceSpawn containerContainerMulti-user, untrusted code
RemoteAPIWorkspaceConnect to URLRemote serverDistributed systems, cloud
Source:

Component Relationships

How Workspace Integrates

Relationship Characteristics:
  • Conversation → Workspace: Conversation factory uses workspace type to select LocalConversation or RemoteConversation
  • Workspace → Agent Server: RemoteWorkspace delegates operations to agent-server API
  • Tools Independence: Tools run in the same environment as workspace

See Also