Skip to content

feat(sandbox): start a sandbox using an Agent Profile's Sandbox Spec - #1601

Merged
rajshah4 merged 3 commits into
mainfrom
agent/prd197-automation-sandbox-spec
Dec 2, 2026
Merged

rajshah4 merged 3 commits into
mainfrom
agent/prd197-automation-sandbox-spec

Conversation

@rajshah4

@rajshah4 rajshah4 commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

HUMAN:

  • A human has tested these changes.

AGENT:

This draft was prepared with AI assistance.


Why

A run can select an Agent Profile, but Automation creates its sandbox before starting the conversation. The sandbox start previously used the owner's default spec even when the selected profile specified a different one.

How the two changes work together

Say the selected Agent Profile calls for an 8 GB sandbox and the usual sandbox has 4 GB.

Stage What happens
Today Enterprise creates the usual 4 GB sandbox. Automation sends the selected profile when it starts the conversation, after the sandbox already exists.
Automation PR Automation sends the selected profile in the sandbox creation request. An Enterprise instance without the new endpoint rejects the request before allocation, and the run shows an upgrade message.
Enterprise PR Enterprise adds the endpoint that looks up the profile's Sandbox Spec and creates the matching sandbox. Existing automation runs continue using the original request until Automation is updated.
Both together Automation sends the profile at sandbox creation, Enterprise starts the 8 GB sandbox, and the conversation runs inside it.

The compatibility cutoff is deployment of the Enterprise PR. Complete that rollout across all Enterprise instances before deploying the Automation PR. Merging the Enterprise PR alone does not add the endpoint to running servers.

Summary

  • Add POST /api/v1/sandboxes/start-with-agent-profile. It resolves the selected profile in the caller's organization and passes the validated spec to the existing sandbox service.
  • A profile without a spec uses the organization default, then the deployment default. An unavailable profile or spec fails before allocation. With Agent Profiles disabled, the route uses the usual sandbox resolution and returns a null profile.
  • The existing sandbox start endpoint and New Chat precedence stay unchanged. Start the review in openhands/app_server/sandbox/sandbox_router.py.

Issue Number

PRD-197

How to Test

uv run pytest tests/unit/app_server/test_sandbox_router_agent_profile.py \
  tests/unit/app_server/test_sandbox_router_agent_profile_db.py \
  tests/unit/app_server/test_sandbox_router.py \
  tests/unit/server/routes/test_service_account_guard.py

The final commit passed 260 focused tests on EKS, including database-backed profile and spec access, quota, and route classification. The previous router returned 405 for the new endpoint without invoking sandbox creation. Fable 5.2 reviewed this exact commit and reported no actionable issues. The tests exercise spec resolution with the runtime allocation backend stubbed. Live validation remains pending.

Video/Screenshots

Enterprise before-and-after Sandbox Spec selection on EKS

Both requests ran against the same database-backed Enterprise fixture on EKS. The original request omitted the profile and returned the organization default, spec-org. The new request included profile small and returned its spec, spec-private-2g. Runtime allocation was stubbed.

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

Complete the Enterprise rollout before deploying the companion Automation change. Custom and script runs with an unlaunchable selected profile fail before allocation. A profile edit between sandbox and conversation start can leave the sandbox on the spec chosen at allocation.


Enterprise server image for this PR:

ghcr.io/openhands/enterprise-server:sha-7988273

POST /api/v1/sandboxes accepts agent_profile_id. The profile resolves as a
conversation launch in the caller's organization would; its sandbox spec wins
over saved defaults, a profile without one gets the org default and then the
deployment's, and an unavailable spec is a 422 before any allocation. The
response echoes agent_profile_id so clients can tell the parameter was applied.

Co-authored-by: openhands <openhands@all-hands.dev>
Address the PRD-197 review. The profile start moves from a query parameter
on POST /api/v1/sandboxes to POST /api/v1/sandboxes/start-with-agent-profile,
so an app server without it answers 404/405 before allocating anything.
POST /api/v1/sandboxes is back to its released shape. Every launch refusal
of the profile keeps its own structured code. Adds database-backed tests
through the real settings store, flag, org binding and spec access,
including personal profiles and a service account.

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

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  openhands/app_server/sandbox
  sandbox_models.py
  sandbox_router.py
Project Total  

This report was generated by python-coverage-comment-action

@rajshah4
rajshah4 marked this pull request as ready for review November 30, 2026 21:48
@all-hands-bot

all-hands-bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Review posted for 7988273c8b01

Verdict: ✅ APPROVED. See the review.

This is an automated status.

@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).

The new POST /api/v1/sandboxes/start-with-agent-profile route looks correct. It applies the same licence check as POST '', resolves the profile through the existing override_agent_profile_id path, and rejects an unlaunchable profile or an inaccessible spec with a 422 before start_sandbox runs. It returns the plain-route behavior with a null profile when Agent Profiles are off. The service-account allowlist entry is present. All GitHub checks on this head pass.

I could not run the focused tests in this workspace, because the repo conftest.py needs a Docker daemon. I relied on the passing CI shards and read the tests instead.

One non-blocking point is on the inline comment: a profile with no spec skips the owner's saved default spec.

✅ APPROVED

LLM profile: unknown · Model: openhands/claude-sonnet-5-5

return StartedSandboxInfo(**info.model_dump(), agent_profile_id=None)
spec_id = user.active_agent_profile_sandbox_spec_id
if spec_id is None:
spec_id = (await sandbox_spec_service.get_default_sandbox_spec()).id

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.

Non-blocking: when the profile names no spec, this passes the organization default as an explicit sandbox_spec_id. resolve_sandbox_spec ranks an explicit id above the owner's saved default_sandbox_spec_id, so that saved default is skipped here. It is honored by POST '' and by the sandbox a conversation start creates. test_profile_without_spec_uses_org_then_deployment_default pins this: the fixture's owner default is spec-personal and the result is the org default.

A profile with no spec expresses no spec preference. An owner who has a personal default and runs an automation with a spec-less profile will move from the personal default to the org default once Automation starts sending the profile. If that is not intended, call sandbox_service.start_sandbox() in this case, so the usual precedence applies, and keep the explicit id only when the profile has a spec. If it is intended, a note about this case in the PR description would help operators.

@aivong-openhands

Copy link
Copy Markdown
Contributor

SaaS impact assessment

Verdict: The PR adds one route and changes no existing route. It works at the config each environment runs. Nothing breaks until Automation calls the route. There is no opt-out.

Result Config Behavior (before → after)
🟡 needs follow-up Automation deployed before this route profile run uses default spec → run fails (404/405)
🟢 unchanged Existing sandbox start routes same → same
🟢 unchanged Agent Profiles off usual sandbox → usual sandbox

Validation: The diff and call sites are static. Each Automation service calls the Enterprise server of its own environment (deploy values). The Agent Profiles flag per environment is not verified. I verified nothing live.

Rollout: No release includes the PR yet. The Enterprise image and the Automation image roll out on separate pins. Roll out Enterprise first. To undo the change, revert the image. The change has no migration.

Changed symbols and call sites
  • start_sandbox_with_agent_profile: new route. Consumer: Automation _create_sandbox, backends/cloud.py.
  • StartedSandboxInfo: new response type.

This analysis was produced by an AI agent (OpenHands) on behalf of @aivong-openhands.

@aivong-openhands

Copy link
Copy Markdown
Contributor

Note

This PR adds a route and breaks nothing. Complete the Enterprise rollout before you deploy the Automation change.

OHE impact assessment

Verdict: The PR adds POST /api/v1/sandboxes/start-with-agent-profile. It changes no existing route, so it works at default config on every deployment. Existing installs see no change until Automation calls the route. There is no opt-out. With Agent Profiles off, the route starts a sandbox on the usual spec and returns a null profile.

Result Deployment Key input Behavior (before → after)
🟡 changed OHE with Automation, after the Automation PR profile selected default spec → profile's spec
🟡 changed Profile with an unavailable spec spec not in org default spec → 422 before allocation
🟢 unchanged OHE default, Agent Profiles off no profile usual sandbox → usual sandbox, null profile
🟢 unchanged POST /sandboxes, New Chat any same request → same result

Validation: The diff and call sites are static (PR head, open PR). The chart pairing of Enterprise and Automation versions is not verified. I verified nothing live. The PR author reports stubbed runtime allocation.

Customer installs:

  • An Automation service on an older Enterprise image gets 404 or 405 for profile runs. See the Automation PR.
  • The new route calls require_can_start_conversation before it starts the sandbox. Not verified: whether this also counts against a quota that the later conversation start counts.

Rollout: The route reaches an install on the next image rollout. To undo it, revert the image. The change has no migration. Deploy the Automation change only after every Enterprise instance runs this route.

Changed symbols and call sites
  • AgentProfileSandboxStartRequest, StartedSandboxInfo (sandbox_models.py): used only by the new route.
  • start_sandbox_with_agent_profile (sandbox_router.py): new route. Consumer: automation backends/cloud.py _create_sandbox.
  • depends_sandbox_spec_service: existing dependency, now also used in sandbox_router.py.

This analysis was produced by an AI agent (OpenHands) on behalf of @aivong-openhands.

@aivong-openhands

Copy link
Copy Markdown
Contributor

I tested this PR on a live install. The cluster is a fresh Replicated Embedded Cluster install that runs the PR's image, ghcr.io/openhands/enterprise-server:sha-7988273.

pr1601-start-with-agent-profile.webm

Setup: the deployment has two Sandbox Specs, v1_current (the default) and pr1601-spec-b. An org Agent Profile, spec-b-profile, names pr1601-spec-b.

The video (80 seconds) shows these calls:

Call Result
POST /api/v1/sandboxes (usual start) sandbox_spec_id: v1_current
POST /api/v1/sandboxes/start-with-agent-profile, Agent Profiles off sandbox_spec_id: v1_current, agent_profile_id: null
The same request, Agent Profiles on sandbox_spec_id: pr1601-spec-b, agent_profile_id is the requested profile
The same request with an unknown profile ID 404 agent_profile_not_found, nothing is started

The sandbox that the profile started reaches RUNNING on pr1601-spec-b.

Notes:

  • Agent Profiles were off for launches on this install at first. I turned them on with the ENABLE_AGENT_PROFILES feature flag, through the admin API.
  • I created pr1601-spec-b as a copy of the default spec with another name. It has the same image, so the test shows which spec the route picks, not a different image or size.
  • I tested the Enterprise server only. I did not test the companion Automation change.
  • Each panel in the video is real command output from the test run. The host, API key and IDs in the displayed commands are placeholders.

@rajshah4
rajshah4 merged commit cec1fc2 into main Dec 2, 2026
30 checks passed
@rajshah4
rajshah4 deleted the agent/prd197-automation-sandbox-spec branch December 2, 2026 01:04
@openhands-release-bot openhands-release-bot Bot added the released: 1.104.0 Shipped in 1.104.0 label Dec 2, 2026
@openhands-release-bot

Copy link
Copy Markdown
Contributor

🚀 Released in 1.104.0.

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

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants