Skip to content

feat: add plugin-backed executable automations - #580

Merged
malhotra5 merged 36 commits into
mainfrom
openhands/plugin-backed-executable-automations
Oct 19, 2026
Merged

malhotra5 merged 36 commits into
mainfrom
openhands/plugin-backed-executable-automations

Conversation

@malhotra5

@malhotra5 malhotra5 commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Summary

Draft implementation for plugin-backed executable automations, following the design direction in #579:

  • Adds POST /api/automation/v1/plugin-spec to create an automation from a plugin source plus schedule/event trigger details.
  • Fetches and validates an automation-plugin.json manifest from the plugin source.
  • Validates plugin config against the manifest's JSON schema.
  • Resolves plugin runtime defaults for agent/LLM profile names and validates selected agent profile IDs when provided.
  • Validates explicit tools on the selected agent profile against an optional runtime.agent_profile.allowed_tools allowlist.
  • Keeps existing model precedence semantics for plugin specs: an agent profile owns model selection, so explicit model plus agent profile is rejected and persisted model is null when an agent profile is selected.
  • Local Agent Canvas profile validation now uses the local agent-server /api/agent-profiles endpoints and forwards X-Session-API-Key.
  • Persists the source plugin spec on automations.plugin_spec.
  • Resolves mutable plugin/runtime attributes at dispatch time and persists them on automation_runs.resolved_runtime.
  • Builds a per-run tarball from the plugin source and injects:
    • .automation/config.json
    • .automation/execution.json
    • .automation/plugins.json
    • AUTOMATION_AGENT_PROFILE_ID
    • AUTOMATION_AGENT_PROFILE_NAME
    • AUTOMATION_LLM_PROFILE_NAME
  • Keeps the initial model executable-script-only. The script can optionally use the SDK to start a conversation, but the service does not treat conversation automations as first-class yet.

Companion example plugin PR: OpenHands/extensions#767.

Setup script behavior

This draft supports setup as an explicit manifest field: entrypoint.setup_script.

  • If setup_script is setup.sh, the plugin's root setup.sh is packaged and the existing executor runs it.
  • If setup_script is another relative path, the service packages a root setup.sh wrapper that invokes it.
  • If setup_script is absent, an undeclared root setup.sh is not packaged, so setup cannot run accidentally.

Things that still need review

  • The manifest format is intentionally small and probably belongs in a shared schema once extensions and automation agree on it.
  • Secondary plugin manifests are currently only fetched/recorded, not auto-loaded into an SDK conversation because this PR is scoped to executable scripts.
  • Profile-name existence can only be validated where auth/user metadata is available. Agent profile IDs are validated through the existing OpenHands API path; agent profile names from manifests are persisted and passed through as env vars.
  • Git sync serialization does not round-trip plugin-spec automations yet, because the goal is to let GitHub-hosted plugins replace backing automation definitions.

Validation

  • uv run ruff check openhands/automation/plugin_specs.py openhands/automation/router.py openhands/automation/dispatcher.py openhands/automation/models.py openhands/automation/utils/run.py tests/test_plugin_specs.py tests/test_router_plugin_spec.py
  • uv run python -m pytest tests/test_plugin_specs.py
  • python -m py_compile openhands/automation/plugin_specs.py openhands/automation/router.py openhands/automation/dispatcher.py openhands/automation/models.py openhands/automation/utils/run.py migrations/versions/033_add_plugin_spec_runtime.py
  • AUTOMATION_DB_URL=sqlite+aiosqlite:////tmp/automation_migration_check.db uv run alembic upgrade head

Attempted but blocked locally because Docker is unavailable in this sandbox:

  • uv run python -m pytest tests/test_plugin_specs.py tests/test_router_plugin_spec.py

This PR was created by an AI agent (OpenHands) on behalf of the user.

@malhotra5 can click here to continue refining the PR

  • Keeps plugin-spec create inputs separated: callers provide plugin source plus scheduling/runtime metadata; plugin config, agent profile, and LLM profile come from the manifest.

  • Rejects duplicate agent-profile names during profile validation before resolving manifest-declared profile requirements.

  • Resolves the manifest-declared agent profile name to its UUID during creation, stores agent_profile_id, and omits the duplicate profile name from persisted plugin_spec.

  • Rejects plugin agent profiles that do not explicitly enable every tool declared in runtime.agent_profile.allowed_tools, and still rejects extra tools.

  • Adds profile allowlist validation for allowed_mcp_server_refs and allowed_secret_refs, matching allowed_tools: the resolved profile must explicitly enable all and only the declared refs.

  • Removes the obsolete runtime.required_secrets manifest field; secrets now flow through agent-profile allowed_secret_refs.

  • Allows PATCH /v1/{automation_id} on plugin-spec automations with a new plugin source/ref, revalidating the manifest and derived runtime fields.

  • Plugin-source PATCH falls back to reusing the existing selected profile when the app server refuses API-key access to agent-profile details, but only if the new manifest keeps the same profile requirements.

Jev-Fast-Audit

⚡ Jev fast audit · estimates · 0.45s · commit 042c143
Strongest signal: Unverified remote execution · 69% estimated likelihood.
Evidence: F005H004 · openhands/automation/dispatcher.py:429–533.
Coverage: ⚠️ reduced context — partial coverage; 22/46 hunks, 13/20 files (context budget: 22, file budget: 7, hunk budget: 24).

All estimates and evidence
Estimate Likelihood / value Direct evidence
SQL injection 3.0% No direct hunk selected
Command injection 34.0% F005H004 · openhands/automation/dispatcher.py:429–533
Weakened authentication 20.0% No direct hunk selected
Weakened authorization 25.0% No direct hunk selected
Contract regression 24.0% No direct hunk selected
Data loss 11.0% No direct hunk selected
Sensitive data disclosure 24.0% No direct hunk selected
Unexpected data transfer 10.0% No direct hunk selected
Credential misuse 34.0% F005H003 · openhands/automation/dispatcher.py:91–236
Untrusted instruction authority 25.0% F009H001 · openhands/automation/presets/plugin_spec/sdk_main.py:1–279
Package source redirection 7.0% No direct hunk selected
Unverified remote execution 69.0% F005H004 · openhands/automation/dispatcher.py:429–533
Privileged environment access 10.0% No direct hunk selected
Security assessment bypass 25.0% No direct hunk selected
Prohibited workload 3.0% No direct hunk selected
Primary concern Unverified remote execution; confidence 85.0% F005H004 · openhands/automation/dispatcher.py:429–533

Co-authored-by: openhands <openhands@all-hands.dev>
@github-actions github-actions Bot added the type: feat A new feature label Oct 12, 2026
@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Warning

Your comment is too long (maximum is 65536 characters), so the coverage report was not added. See the job log for how to reduce it.

Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
Comment thread openhands/automation/plugin_specs.py Resolved
Comment thread openhands/automation/plugin_specs.py Resolved

@Fieldnote-Echo Fieldnote-Echo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would keep this PR in draft. Three security boundaries need correction.

  1. The service validates the selected agent profile during creation, but the stock runner does not use it. The runner builds a default agent and loads unscoped secrets and MCP settings. A profile allowlist therefore does not control the run.
  2. Plugin source URLs can contain inline credentials. The service stores and forwards the full source value. This can expose the credential through stored runtime data, API output, run files, logs, errors, and the Git origin.
  3. The Automation Service preflights user-selected plugin sources with local sources enabled. This lets an input reach local paths or loopback services before sandbox creation.

The smallest safe scope is:

  • Start the conversation through the selected agent profile. Fail if the profile cannot resolve at dispatch time.
  • Reject HTTP and HTTPS URL userinfo. Use public sources only until private Git has a separate scoped credential reference.
  • Reject local and file:// sources in cloud mode. Run remote preflight in an isolated boundary, or enforce the allowed host, resolved IP address, and each redirect.

Co-authored-by: openhands <openhands@all-hands.dev>
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

🧹 PR Artifact Cleanup Queued

The .pr/ directory reached main after merge. A cleanup PR has been opened or updated: #599

Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
Comment thread openhands/automation/schemas.py Resolved
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This review was posted by an AI agent (OpenHands).

Scope: this change belongs in this repository. It adds an automation definition type, dispatch preflight, and per-run sandbox packaging, which AGENTS.md assigns to the Automation Service. The manifest schema is still noted as provisional and shared with OpenHands/extensions; no scope handoff is needed.

State reviewed fresh on head 042c1435, base 15abe6bb (mergeable: true, mergeable_state: behind; behind main, not conflicted). CI on this head is green: unit-tests, backend, Build and Push Automation Image, check-pr-artifacts, and both pr-title jobs succeeded. This account had not reviewed this head; my previous review was on 2100227d.

The three material findings from my earlier reviews are fixed and now extended:

  1. Transient profile-API failure no longer permanently disables. _is_retryable_http_status classifies 408/429/5xx as retryable and the preflight except HTTPException handler records a transient failure without disable=True.
  2. Transient plugin-source failures no longer permanently disable. preflight_manifest now preserves the SDK's PluginSourceError code/status_code on PluginSpecError (source_unavailable -> 502, timeout -> 504, everything else -> 422), and the new except PluginSpecError branch treats a retryable status_code as a transient run failure instead of disabling the automation. Permanent 4xx manifest/config errors still disable.
  3. The sandbox created before plugin fetch is no longer leaked on a transient fetch error: the except httpx.HTTPError handler awaits backend.release_context(client, ctx) before _fail, matching the sibling release sites.

Verification on this head: uv run ruff check openhands/automation/ and the changed test files pass, py_compile passes on every changed module, and tests/test_plugin_specs.py + tests/test_model_profiles.py pass (27 passed). The Docker-backed router/dispatcher tests still error at fixture setup because Docker is unavailable in this sandbox (unix-socket FileNotFoundError), not because of this change. I also confirmed the released pin openhands-sdk==1.55.1 exports the new PluginSourceError import, uv.lock is at revision = 5, and the SDK's StartConversationRequest accepts the agent_profile_id/plugins/workspace kwargs the rewritten stock runner passes.

The runner rewrite (sdk_main.py -315 lines, new prompt_builder.py) drops repo cloning and the finish-tool hook and always launches through the selected agent profile. That is consistent with this PR's stated executable-script scope: plugin-spec requests have no repos field, the conversation-runner manifest now requires a runtime.agent_profile, and the runner raises when AUTOMATION_AGENT_PROFILE_ID is absent, so the removed branches were unreachable. normalize_keep_alive_for_trigger was inlined into CreateAutomationRequest and the plugin-spec create path with equivalent semantics, and no stale references remain outside the other presets that still use their own helpers.

Non-blocking, unchanged and still not exploitable today: preflight_manifest, validate_required_plugins, and build_execution_payload default allow_local_sources: bool = True (plugin_specs.py:399,589,621), so the cloud-mode guard fails open for any future caller that omits the argument. Every current caller passes it explicitly (router.py:418,422, dispatcher.py:450). Defaulting to False would make the safe path the default, but this does not block the change.

✅ APPROVED

@jpshackelford
jpshackelford self-requested a review October 16, 2026 18:57

@jpshackelford jpshackelford left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a super valuable change--hard to overstate what a tremendous usability improvement this is for automations.

I've been following this since #579 was posted and it has come a very long way. I especially love:

  • Install-time parameters. config is accepted at create, validated against the manifest's config_schema, and has defaults applied. One recipe can now serve many teams without a fork.
  • suggested_trigger (and suggested_trigger_template). A recipe can carry a sensible default schedule, and the template form lets an adopter's config shape the trigger.
  • One manifest. The definition lives under .plugin/plugin.json → automation, so there's one file and one plugin to learn rather than two.
  • entrypoint.runner. script and conversation let a recipe be either a plain script or "run this plugin command" through an agent profile. That gives plugin authors a straightforward way to say which command to call.

Awesome.

I noticed a few things that could be addressed in a follow-on.

1. Does config reach a conversation runner's conversation?
As far as I can tell it doesn't. .automation/config.json is written into the tarball and used to render suggested_trigger_template, but sdk_main.py and prompt_builder.py never read AUTOMATION_CONFIG_PATH, and entrypoint.arguments is passed through as-is. With arguments: "repo={{ config.repository }}" and config={"repository": "acme/widgets"}, the generated prompt.txt is literally /demo:run repo={{ config.repository }}. The E2E runs in .pr/README.md set a config message but failed on LLM auth, so they don't show whether the agent ever saw it. Should arguments be rendered with the same {{ config.* }} templates the trigger uses, or should the config go into the prompt?

2. Defaulting to entry_command.
I really like that entrypoint.command keeps the semantics of the entry_command that is supported by plugin launching today (for the conversation runner). And I think it is really smart that a plugin could set these to distinct commands so that interactive experience or launch experience is different from automation experience. That said, I think it might also be nice if one could allow conversation automations to fallback to using the entry_command so that one could make a plugin automation-ready by adding an automation block that only names the runner and the agent profile. If neither is set, the manifest would still be rejected with the same "command is required" error.

3. Updating config.
PATCH has no config field (extra="forbid" rejects it), so config can only be set at create. An update that changes plugin.ref revalidates the stored config against the new manifest, and the existing update test only covers config: {}. Is "config is fixed at create" intended? If so, a test with a non-empty config surviving a ref update would document that.

4. Private plugins.
_fetch_plugins_on_agent_server sends only source, ref and repo_path to /api/plugins/fetch, but the endpoint also accepts secrets for ${VAR} placeholders in source and ref. I couldn't see a path that supplies them, so I'd expect recipes in private repos to fail at dispatch. Is that planned as a follow-on?

This comment was drafted with the help of an AI agent (OpenHands) on behalf of John-Mason Shackelford.

@malhotra5

Copy link
Copy Markdown
Member Author

Thanks for the comments @jpshackelford! I think all of these make sense and I'd be happy to implement them as followups

@malhotra5
malhotra5 merged commit 2a6a779 into main Oct 19, 2026
8 checks passed
@openhands-release-bot openhands-release-bot Bot added the released: 1.21.0 Shipped in 1.21.0 label Oct 19, 2026
@openhands-release-bot

Copy link
Copy Markdown
Contributor

🚀 Released in 1.21.0.

@juanmichelini

juanmichelini commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Awesome tested on staging with

curl -X POST https://staging.all-hands.dev/api/automation/v1/plugin-spec \
  -H "Authorization: Bearer $OPENHANDS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "hello-world-automation",
    "plugin": {
      "source": "github:OpenHands/extensions",
      "ref": "openhands/automation-plugin-hello-world-script-runner",
      "repo_path": "plugins/hello-world-automation"
    },
    "config": {},
    "trigger": {
      "type": "cron",
      "schedule": "0 9 * * *",
      "timezone": "UTC"
    }
  }'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released: 1.21.0 Shipped in 1.21.0 type: feat A new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants