Skip to main content

Workspace

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: faheemcode/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 faheemcode-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