Skip to content

Local control: in-SDK sidecar for user_device environments#161

Open
abonneth wants to merge 2 commits into
mainfrom
antoine/local-control
Open

Local control: in-SDK sidecar for user_device environments#161
abonneth wants to merge 2 commits into
mainfrom
antoine/local-control

Conversation

@abonneth

@abonneth abonneth commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Note

Medium Risk
New subprocess/network loop with API credentials and optional desktop/browser control increases attack and operational surface, but behavior is gated by user_device envs, optional extras, and HAI_AUTO_SIDECAR with broad unit test coverage.

Overview
Adds local control so agents with host: user_device environments can drive this machine’s browser or desktop via an in-process sidecar, instead of relying only on remote sandboxes.

The SDK now rewrites agent/session payloads: user_device envs get a deterministic session_id (from API key + env id + capability) so the cloud can route commands to the right channel. Client / AsyncClient use wrapped agents and sessions clients that apply this wiring on create/update/patch and, when HAI_AUTO_SIDECAR is on (default), start sidecars before create_session (including after fetching a named agent).

New hai_agents.local runs background sidecars that long-poll the API, execute driver methods through hai-drivers (Selenium + optional Chrome launch for browser; desktop extra for local desktop), and post results—with retries, idempotent command_uid caching, and one browser / one desktop per machine (in-process and cross-process lock files).

pip install 'hai-agents[browser]' / [desktop] pull in hai-drivers; the CLI adds hai local browser / hai local desktop for manual sidecars when sessions start elsewhere.

Tests cover wiring, auto-start, protocol, and runtime rollback; integration tests disable auto sidecars by default.

Reviewed by Cursor Bugbot for commit edc1765. Bugbot is set up for automated code reviews on this repo. Configure here.

@abonneth abonneth marked this pull request as ready for review June 29, 2026 18:15
@abonneth abonneth requested a review from adeprezh as a code owner June 29, 2026 18:15
@abonneth abonneth requested a review from cm2435-hcomp July 3, 2026 11:17
@hcompai hcompai deleted a comment from cm2435 Jul 3, 2026
Comment thread src/hai_agents/local/runtime.py
Comment thread pyproject.toml
]
browser = [
"hai-drivers[web]>=0.1.0",
]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lock omits hai-drivers package

High Severity

Optional browser and desktop extras declare hai-drivers, but uv.lock still resolves direct selenium/pyautogui pins and never installs hai-drivers, while SidecarClient._build_driver imports hai_drivers.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit fa3ff61. Configure here.

Comment thread src/hai_agents/local/runtime.py
@abonneth abonneth force-pushed the antoine/local-control branch 2 times, most recently from 14ca56a to bf57eb3 Compare July 3, 2026 14:11
@abonneth abonneth changed the title Local control: in-SDK sidecar + desktop/browser drivers Local control: in-SDK sidecar for user_device environments Jul 3, 2026
@hcompai hcompai deleted a comment from cursor Bot Jul 3, 2026
@hcompai hcompai deleted a comment from cursor Bot Jul 3, 2026
@hcompai hcompai deleted a comment from cursor Bot Jul 3, 2026
@hcompai hcompai deleted a comment from cursor Bot Jul 3, 2026
@hcompai hcompai deleted a comment from cursor Bot Jul 3, 2026
@hcompai hcompai deleted a comment from cursor Bot Jul 3, 2026
@hcompai hcompai deleted a comment from cursor Bot Jul 3, 2026
@hcompai hcompai deleted a comment from cursor Bot Jul 3, 2026
@hcompai hcompai deleted a comment from cursor Bot Jul 3, 2026
@hcompai hcompai deleted a comment from cursor Bot Jul 3, 2026
@hcompai hcompai deleted a comment from cursor Bot Jul 3, 2026
@hcompai hcompai deleted a comment from cursor Bot Jul 3, 2026
@hcompai hcompai deleted a comment from cursor Bot Jul 3, 2026
@hcompai hcompai deleted a comment from cursor Bot Jul 3, 2026
@hcompai hcompai deleted a comment from cursor Bot Jul 3, 2026
Comment thread src/hai_agents/local/chrome.py
@hcompai hcompai deleted a comment from cursor Bot Jul 3, 2026
@hcompai hcompai deleted a comment from cursor Bot Jul 3, 2026
@hcompai hcompai deleted a comment from cursor Bot Jul 3, 2026
@hcompai hcompai deleted a comment from cursor Bot Jul 3, 2026
@hcompai hcompai deleted a comment from cursor Bot Jul 3, 2026
@hcompai hcompai deleted a comment from cursor Bot Jul 3, 2026
@hcompai hcompai deleted a comment from cursor Bot Jul 3, 2026
@hcompai hcompai deleted a comment from cursor Bot Jul 3, 2026
@hcompai hcompai deleted a comment from cursor Bot Jul 3, 2026
@hcompai hcompai deleted a comment from cursor Bot Jul 3, 2026
@hcompai hcompai deleted a comment from cursor Bot Jul 3, 2026
@hcompai hcompai deleted a comment from cursor Bot Jul 3, 2026
@hcompai hcompai deleted a comment from cursor Bot Jul 3, 2026
@hcompai hcompai deleted a comment from cursor Bot Jul 3, 2026
@hcompai hcompai deleted a comment from cursor Bot Jul 3, 2026
@hcompai hcompai deleted a comment from cursor Bot Jul 3, 2026
@hcompai hcompai deleted a comment from cursor Bot Jul 3, 2026
@abonneth abonneth force-pushed the antoine/local-control branch from bf57eb3 to 6e6cc3f Compare July 3, 2026 14:20
Comment thread src/hai_agents/client.py
Comment thread src/hai_agents/local/runtime.py
@abonneth abonneth force-pushed the antoine/local-control branch from 6e6cc3f to f5bd8db Compare July 3, 2026 14:39
Agents with a user_device environment are served by an in-SDK sidecar that
long-polls the Agent Platform for driver commands and executes them on this
machine via hai-drivers (Selenium attached to Chrome's debug port for browser,
pyautogui/pynput for desktop). Sidecars start automatically on create_session
and are also available via `hai local browser|desktop`.

Co-authored-by: Cursor <cursoragent@cursor.com>
@abonneth abonneth force-pushed the antoine/local-control branch from f5bd8db to b2762ab Compare July 3, 2026 16:17

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b2762ab. Configure here.

Comment thread src/hai_agents/client.py
agent = kwargs["agent"]
if isinstance(agent, str):
try:
agent = AgentsClient(client_wrapper=wrapper).get_agent(agent)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Named agent fetch skips resolve

Medium Severity

When create_session is given a catalog agent name and auto sidecars are enabled, the SDK loads the definition with get_agent but does not pass resolve=true. Unresolved string subagent or environment leaves never expose user_device configs, so collect_sidecar_configs can skip required local sidecars while the session still starts.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit b2762ab. Configure here.

…ayer

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant