Skip to main content
The API-sandboxed agent server demonstrates how to use APIRemoteWorkspace to connect to a OpenHands runtime API service. This eliminates the need to manage your own infrastructure, providing automatic scaling, monitoring, and secure sandboxed execution.

Basic Example

This example shows how to connect to a hosted runtime API for fully managed agent execution:
examples/02_remote_agent_server/04_convo_with_api_sandboxed_server.py
Running the Example

Key Concepts

APIRemoteWorkspace

The APIRemoteWorkspace connects to a hosted runtime API service:
This workspace type:
  • Connects to a remote runtime API service
  • Automatically provisions sandboxed environments
  • Manages container lifecycle through the API
  • Handles all infrastructure concerns

Runtime API Authentication

The example requires a runtime API key for authentication:
This key authenticates your requests to the hosted runtime service.

Pre-built Image Selection

You can specify which pre-built agent server image to use:
The runtime API will pull and run the specified image in a sandboxed environment.

Workspace Testing

Just like with DockerWorkspace, you can test the workspace before running the agent:
This verifies connectivity to the remote runtime and ensures the environment is ready.

Automatic RemoteConversation

The conversation uses WebSocket communication with the remote server:
All agent execution happens on the remote runtime infrastructure.

Next Steps