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:
- Execution Abstraction - Unified interface for command execution across environments
- File Operations - Upload, download, and manipulate files in workspace
- Resource Management - Context manager protocol for setup/teardown
- Environment Isolation - Separate agent execution from host system
Architecture
Key components
| Component | Purpose | Design |
|---|---|---|
BaseWorkspace | Abstract interface | Defines execution and file operation contracts |
LocalWorkspace | Local execution | Subprocess-based command execution |
RemoteWorkspace | Remote execution | HTTP API-based execution via agent-server |
CommandResult | Execution output | Structured result with stdout, stderr, exit_code |
FileOperationResult | File op outcome | Success status and metadata |
Workspace types
Local vs remote execution
| Aspect | LocalWorkspace | RemoteWorkspace |
|---|---|---|
| Execution | Direct subprocess | HTTP → agent-server |
| Isolation | Process-level | Container/VM-level |
| Performance | Fast (no network) | Network overhead |
| Security | Host system access | Sandboxed |
| Use Case | Development, CLI | Production, web apps |
Core operations
Command execution
Command Result Structure:
| Field | Type | Description |
|---|---|---|
| stdout | str | Standard output stream |
| stderr | str | Standard error stream |
| exit_code | int | Process exit code (0 = success) |
| timeout | bool | Whether command timed out |
| duration | float | Execution time in seconds |
File operations
| Operation | Local Implementation | Remote Implementation |
|---|---|---|
| Upload | shutil.copy() | POST /file/upload with multipart |
| Download | shutil.copy() | GET /file/download stream |
| Result | FileOperationResult | FileOperationResult |
Resource management
Workspaces use context manager for safe resource handling:
Lifecycle Hooks:
| Phase | LocalWorkspace | RemoteWorkspace |
|---|---|---|
| Enter | Create working directory | Connect to agent-server, verify |
| Use | Execute commands | Proxy commands via HTTP |
| Exit | No cleanup (persistent) | Disconnect, optionally stop container |
Remote workspace extensions
The SDK provides remote workspace implementations in faheemcode-workspace package:
Implementation Comparison:
| Type | Setup | Isolation | Use Case |
|---|---|---|---|
| LocalWorkspace | Immediate | Process | Development, trusted code |
| DockerWorkspace | Spawn container | Container | Multi-user, untrusted code |
| RemoteAPIWorkspace | Connect to URL | Remote server | Distributed systems, cloud |
Source:
- DockerWorkspace:
faheemcode-workspace/faheemcode/workspace/docker - RemoteAPIWorkspace:
faheemcode-workspace/faheemcode/workspace/remote_api
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
- Conversation Architecture - How workspace type determines conversation implementation
- Agent Server - Remote execution API
- Tool System - Tools that use workspace for execution