Skip to content

πŸ™Œ OpenHands: AI-Driven Development

20.6 KB
Raw Blame

F14 β€” Secrets

Secrets are named values the agent can use during conversations. A user lists, adds, edits and deletes them under Settings β†’ Secrets; saved values are never shown again, and every new conversation receives them as environment variables.

Source: src/routes/secrets-settings.tsx, src/components/features/settings/secrets-settings/, src/api/secrets-service.ts, src/components/features/conversation/secret-request-card.tsx, src/services/secret-request.ts, src/stores/secret-request-store.ts, src/constants/secret-request.ts, src/api/request-secret-client-tool.ts.

Sub-features

  • F14.list: the Secrets page lists each secret's name and description with Edit and Delete actions; the launcher-seeded OPENHANDS_AUTOMATION_API_KEY is always present.
  • F14.create: adding a secret persists it; it is listed after a reload.
  • F14.create-validation: duplicate names, names that break ^[a-zA-Z][a-zA-Z0-9_]{0,63}$ and empty values are refused with a message.
  • F14.edit: editing the description with the value left blank keeps the stored value; Save stays disabled until something changes.
  • F14.delete: deleting asks for confirmation; Cancel keeps the row, Confirm removes it for good.
  • F14.agent-access: a conversation started after the secret was saved sees it as an environment variable.
  • F14.phone: the page and its forms fit a 390 px viewport without horizontal overflow.
  • F14.form-back: the Add and Edit forms replace the list with an Add a Secret / Edit a Secret title and a Back button; Back (like Cancel) returns to the list and discards the draft.
  • F14.rename: the Edit form's name is editable; renaming with the value left blank keeps the stored value under the new name, and renaming onto an existing name is refused with Secret already exists.
  • F14.edit-value: typing a value in the Edit form (labelled "Secret Value (leave blank to preserve the existing value)") replaces the stored value for new conversations.
  • F14.delete-escape: Escape closes the delete confirmation without deleting.
  • F14.agent-request: in a local conversation the agent's request_secret tool adds a The agent needs a secret card in the chat, right after the tool call, with its reason and the name prefilled; it does not block the conversation, so the agent can keep working and the user answers when ready. Add secret saves it, attaches it to the running conversation and reports saved to the agent, Cancel reports not_saved, and a name that is already saved is attached without a card. The value never reaches the agent's events.

How to get to it (user POV)

  • Sidebar settings gear (backend-selector-settings-link), then Secrets in the settings navigation (sidebar-settings-/settings/secrets).
  • Direct URL /settings/secrets.
  • Command menu (Control+k or Meta+k, or command-menu-trigger in the sidebar): search "Secrets", choose Secrets settings.
  • The agent itself, in a conversation: its request_secret client tool adds the request card (testid=secret-request-card) to the chat on /conversations/<id> (F14.agent-request).

Driving it with control-openhands

Preconditions:

  • Baseline state (launched, doctored, onboard --skip done).

  • No secret named QA_TMP_SECRET, QA_AGENT_SECRET, QA_RENAMED_SECRET or QA_BACK_SECRET exists (control-openhands api GET /api/settings/secrets).

  • F14.agent-access, F14.rename, F14.edit-value and F14.agent-request need an active LLM profile (control-openhands llm preset deepseek).

  • No secret named QA_REQ_SECRET or QA_REQ_CANCEL exists, for F14.agent-request.

  • Open the list (F14.list). Navigate from the sidebar. Run control-openhands browser click 'testid=backend-selector-settings-link', control-openhands browser click 'testid=sidebar-settings-/settings/secrets', then control-openhands browser count 'testid=secret-item >> has-text=OPENHANDS_AUTOMATION_API_KEY'. The count is 1 and the URL is /settings/secrets.

  • Command-menu entry (F14.list). Run control-openhands browser goto / (the previous bullet left /settings/secrets, which would make the URL check pass vacuously), then control-openhands browser press Control+k, control-openhands browser type 'testid=command-menu >> role=combobox' Secrets, control-openhands browser press Enter, then control-openhands browser url. The URL ends in /settings/secrets.

  • Create (F14.create). Run control-openhands browser click 'testid=add-secret-button', control-openhands browser fill 'testid=add-secret-form >> testid=name-input' QA_TMP_SECRET, control-openhands browser fill 'testid=add-secret-form >> testid=value-input' dummy-value-123, control-openhands browser fill 'testid=add-secret-form >> testid=description-input' 'QA dummy', control-openhands browser click 'testid=add-secret-form >> testid=submit-button', then control-openhands browser reload and control-openhands browser count 'testid=secret-item >> has-text=QA_TMP_SECRET'. The count is 1 after the reload.

  • Duplicate name (F14.create-validation). Run control-openhands browser click 'testid=add-secret-button', fill name-input with QA_TMP_SECRET and value-input with other as above, click testid=add-secret-form >> testid=submit-button, then control-openhands browser snapshot 'testid=add-secret-form'. The snapshot shows the paragraph Secret already exists and the form stays open. The paragraph uses the theme's danger colour (#18199): control-openhands browser eval "getComputedStyle([...document.querySelectorAll('[data-testid=add-secret-form] p')].find(e=>e.innerText==='Secret already exists')).color" is rgb(231, 106, 94) on OpenHands-Neutral and rgb(209, 52, 56) on Light+ (F16.color-theme).

  • Invalid name (F14.create-validation). In the same form run control-openhands browser fill 'testid=add-secret-form >> testid=name-input' 'bad name!', click submit, then control-openhands browser eval "document.querySelector('[data-testid=add-secret-form] [data-testid=name-input]').validationMessage". The value is the browser's pattern message (Please match the requested format. in Chromium) and no secret is created (api GET /api/settings/secrets). Close with control-openhands browser click 'testid=add-secret-form >> testid=cancel-button'.

  • Empty value (F14.create-validation). Run control-openhands browser click 'testid=add-secret-button', fill testid=add-secret-form >> testid=name-input with QA_EMPTY_VALUE and leave value-input empty. control-openhands browser enabled 'testid=add-secret-form >> testid=submit-button' is false, and control-openhands browser eval "document.querySelector('[data-testid=add-secret-form] [data-testid=value-input]').validationMessage" is Please fill out this field. Close with testid=add-secret-form >> testid=cancel-button; api GET /api/settings/secrets lists no QA_EMPTY_VALUE.

  • Edit keeps the value (F14.edit). Run control-openhands browser click 'testid=secret-item >> has-text=QA_TMP_SECRET >> testid=edit-secret-button', control-openhands browser value 'testid=edit-secret-form >> testid=value-input' (empty) and control-openhands browser enabled 'testid=edit-secret-form >> testid=submit-button' (false). Fill testid=edit-secret-form >> testid=description-input with QA dummy edited; enabled turns true. Click testid=edit-secret-form >> testid=submit-button, control-openhands browser reload, then control-openhands browser text 'testid=secret-item >> has-text=QA_TMP_SECRET'. The row text is QA_TMP_SECRET and QA dummy edited separated by a tab ("QA_TMP_SECRET\tQA dummy edited" in the JSON output).

  • Delete with confirmation (F14.delete). Run control-openhands browser click 'testid=secret-item >> has-text=QA_TMP_SECRET >> testid=delete-secret-button'; the dialog testid=confirmation-modal reads Are you sure you want to delete this key?. Run control-openhands browser click 'testid=confirmation-modal >> testid=cancel-button'; the row count stays 1. Repeat the delete click, then control-openhands browser click 'testid=confirmation-modal >> testid=confirm-button', control-openhands browser reload and control-openhands browser count 'testid=secret-item >> has-text=QA_TMP_SECRET'. The count is 0.

  • Agent receives the secret (F14.agent-access). Create QA_AGENT_SECRET with value qa-dummy-4821 through the form as in Create. Run control-openhands conversation start --prompt "Run exactly this command and reply with only its output: python3 -c \"import os; print(os.environ.get('QA_AGENT_SECRET') == 'qa-dummy-4821')\"" --wait --timeout 240, then control-openhands conversation events <id> --kinds ObservationEvent. The terminal observation's text is True. Assert the observation, not the agent's reply: deepseek-flash often declines to echo anything about a secret (see Gotchas). Keep QA_AGENT_SECRET for Rename and Replace value below; they delete it.

  • Phone layout (F14.phone). Run control-openhands browser goto /settings/secrets (conversation start left the browser on the conversation), control-openhands browser viewport phone, control-openhands browser bbox 'testid=secrets-settings-screen' and control-openhands browser screenshot --feature F14.phone --name list. insideViewport is true and pageHorizontalOverflow is false; the screenshot shows the table with Edit and Delete icons. Then control-openhands browser click 'testid=add-secret-button', control-openhands browser bbox 'testid=add-secret-form' (insideViewport true, no page overflow) and control-openhands browser screenshot --feature F14.phone --name add-form; cancel the form. Return with control-openhands browser viewport desktop.

  • Back discards the draft (F14.form-back). On /settings/secrets run control-openhands browser click 'testid=add-secret-button' and control-openhands browser text 'testid=secret-editor-title' (Add a Secret). Fill testid=add-secret-form >> testid=name-input with QA_BACK_SECRET and value-input with dummy, then control-openhands browser click 'testid=back-to-secrets'. control-openhands browser count 'testid=add-secret-form' is 0, the list is back (browser count 'testid=secret-item' > 0) and control-openhands api GET /api/settings/secrets lists no QA_BACK_SECRET. Reopening Add shows an empty name-input (browser value); leave with testid=back-to-secrets. The Edit form shows Edit a Secret in the same secret-editor-title.

  • Rename keeps the value (F14.rename). Needs QA_AGENT_SECRET from Agent receives the secret. Run control-openhands browser goto /settings/secrets, control-openhands browser click 'testid=secret-item >> has-text=QA_AGENT_SECRET >> testid=edit-secret-button', fill testid=edit-secret-form >> testid=name-input with OPENHANDS_AUTOMATION_API_KEY and click testid=edit-secret-form >> testid=submit-button: control-openhands browser snapshot 'testid=edit-secret-form' shows the paragraph Secret already exists and the form stays open. Fill name-input with QA_RENAMED_SECRET (value left blank), click submit, control-openhands browser reload; browser count 'testid=secret-item >> has-text=QA_RENAMED_SECRET' is 1, the QA_AGENT_SECRET count is 0, and api GET /api/settings/secrets lists only the new name. Then run control-openhands conversation start --prompt "Run exactly this command and reply with only its output: python3 -c \"import os; print(os.environ.get('QA_RENAMED_SECRET') == 'qa-dummy-4821', 'QA_AGENT_SECRET' in os.environ)\"" --wait --timeout 240 and control-openhands conversation events <id> --kinds ObservationEvent: the observation is True False.

  • Replace the value (F14.edit-value). Run control-openhands browser goto /settings/secrets, control-openhands browser click 'testid=secret-item >> has-text=QA_RENAMED_SECRET >> testid=edit-secret-button' and control-openhands browser snapshot 'testid=edit-secret-form' (the value textbox is named Secret Value (leave blank to preserve the existing value)). Fill testid=edit-secret-form >> testid=value-input with qa-dummy-7350; browser enabled 'testid=edit-secret-form >> testid=submit-button' is true. Click submit; browser count 'testid=edit-secret-form' is 0. Start a conversation with the prompt Run exactly this command and reply with only its output: python3 -c "import os; print(os.environ.get('QA_RENAMED_SECRET') == 'qa-dummy-7350')" (quoted as above) and read its ObservationEvent: True.

  • Agent requests a secret (F14.agent-request). Run control-openhands browser goto /, then control-openhands conversation start --prompt "Call the request_secret tool with name QA_REQ_SECRET and reason 'QA check: a dummy token for verification.' Do not run any other tools. After calling it, end your turn and wait." --wait --timeout 240 (prints <req-id>; it leaves the browser on the conversation). control-openhands conversation events <req-id> --kinds ActionEvent,ObservationEvent shows the request_secret action and the observation Tool call dispatched to client.; control-openhands browser snapshot 'testid=secret-request-card' reads region "The agent needs a secret", the reason QA check: a dummy token for verification., textbox Name holding QA_REQ_SECRET, Value, Description Optional, Cancel and Add secret [disabled] (browser screenshot --feature F14.agent-request --name card). The chat input stays usable while the card is pending, and control-openhands browser reload keeps the card with the name still prefilled. Run control-openhands browser fill 'testid=secret-request-card >> testid=value-input' qa-dummy-5190 and control-openhands browser click 'testid=secret-request-card >> testid=submit-button': the card disappears, control-openhands api GET /api/settings/secrets lists QA_REQ_SECRET, and after control-openhands conversation wait <req-id> --fresh --timeout 180 control-openhands conversation events <req-id> --kinds MessageEvent holds the user message [secret-request] {"status":"saved","name":"QA_REQ_SECRET"}, which the chat does not show (browser count 'text=[secret-request]' is 0). The running conversation now has the value: control-openhands conversation send <req-id> --prompt "Run exactly this command and reply with only its output: python3 -c \"import os; print(os.environ.get('QA_REQ_SECRET') == 'qa-dummy-5190')\"" --wait --timeout 240, then the last terminal ObservationEvent is True. Cancel: browser goto /, start a second conversation with the same prompt naming QA_REQ_CANCEL and reason QA cancel check., fill value-input with should-not-save and control-openhands browser click 'testid=secret-request-card >> testid=cancel-button': the card disappears, api GET /api/settings/secrets lists no QA_REQ_CANCEL, the agent receives [secret-request] {"status":"not_saved","name":"QA_REQ_CANCEL","guidance":...}, and a reload does not bring the card back. Already saved: a third conversation asking for QA_REQ_SECRET again shows no card (browser count 'testid=secret-request-card' 0) and its events hold [secret-request] {"status":"saved","name":"QA_REQ_SECRET"}. At phone width the card fits the chat column (insideViewport true, x 16 and width 358 at 390 px, no page overflow) with the title, every field and both buttons; the block below checks it. Return with browser viewport desktop. QA_REQ_SECRET is deleted in the cleanup below.

    control-openhands browser viewport desktop
    control-openhands browser goto /
    control-openhands conversation start --prompt "Call the request_secret tool with name QA_REQ_PHONE and reason 'QA phone check.' Do not run any other tools. After calling it, end your turn and wait." --wait --timeout 240
    control-openhands browser wait 'testid=secret-request-card'
    control-openhands browser viewport phone
    control-openhands browser screenshot --feature F14.agent-request --name phone-width
    control-openhands assert --field insideViewport --equals true -- browser bbox 'testid=secret-request-card'
    control-openhands browser click 'testid=secret-request-card >> role=button[name="Cancel"]'
    control-openhands browser wait 'testid=secret-request-card' --state detached
    
  • Escape cancels delete (F14.delete-escape). Run control-openhands browser goto /settings/secrets, control-openhands browser click 'testid=secret-item >> has-text=QA_RENAMED_SECRET >> testid=delete-secret-button', control-openhands browser press Escape, then control-openhands browser count 'testid=confirmation-modal' (0) and browser count 'testid=secret-item >> has-text=QA_RENAMED_SECRET' (1). Clean up: delete QA_RENAMED_SECRET and then QA_REQ_SECRET (from F14.agent-request), each with delete-secret-button β†’ testid=confirmation-modal >> testid=confirm-button, browser reload; api GET /api/settings/secrets lists only OPENHANDS_AUTOMATION_API_KEY.

  • Cipher mismatch refuses mutation (F14.create, F14.edit, F14.delete). This is an external-state fixture, not a credential test. Arrange two own dummy secrets and a dummy loopback LLM key; privately back up the run-owned encryption-key, settings.json and secrets.json. Replace only the own cipher file with a newly generated value (never display it), restart and doctor. After bootstrap, restore the old encrypted store bytes under the replacement cipher to isolate the UI write. Add a new dummy secret through the real Secrets form, and inspect only boolean preservation metadata / availability of the old dummy value privately. Independently restore the encrypted settings baseline and change Sound Notifications through Application β†’ Save. Expected: reject writes when existing encrypted state cannot decrypt, preserving it. Known failure, reproduced 2026-10-12 (OpenHands/software-agent-sdk#5622): the secret create succeeds and rewrites an old entry while its dummy value is unavailable (getter 404, name still listed); two unrelated settings saves persist the old LLM key as null. Repeat with a fresh replacement cipher. Immediately restore the original cipher and both stores in finally, restart and doctor; original state must be readable again. This drives secret creation and settings Save, not every edit/delete permutation. Keep all cipher bytes, values and raw store snapshots private.

Gotchas

  • Settings nav test ids embed the route, slashes included: sidebar-settings-/settings/secrets. Quote the selector as written.

  • The value editor is a plain textarea, not a password field: use dummy values only, and never ask the agent to print a real secret.

  • Edit forms intentionally show an empty value; that is not data loss.

  • The invalid-name check is native browser validation. It shows a tooltip that screenshots do not capture, and it leaves any earlier Secret already exists paragraph on screen. Assert with validationMessage and the API, not the paragraph.

  • The model is the weak link in the agent checks, not the product: asked to print a secret's length or last characters, deepseek-flash replies "I can't run that one" and runs nothing, and even for the equality check it may refuse to repeat True in its reply. Use the equality prompt and read the terminal ObservationEvent; conversation events truncates message text to about 160 characters.

  • The conversation Overview has no Secrets entry point: its "..." menu (conversation-overview-ellipsis) offers Workspace and Git sections only.

  • There is no empty state to reach safely: secrets-empty renders only with zero secrets, which means deleting the launcher-seeded key (see below).

  • Secrets saved in Settings reach only conversations started after the save. Reuse an older conversation and the variable is missing. Only request_secret (F14.agent-request) attaches a secret to a running conversation, and only on a local backend.

  • request_secret is registered on every new OpenHands-agent conversation this frontend launches (not on ACP agents or older conversations) and appears in Show Agent Tools & Metadata (see F07.agent-tools-modal). The agent learns the outcome from a hidden [secret-request] ... user message; read it with conversation events <id> --kinds MessageEvent, not from the chat.

  • At 390 px the name column truncates long names (OPEN…); use browser text on the row rather than the screenshot to read a name.

  • OPENHANDS_AUTOMATION_API_KEY is seeded by the launcher for automations; deleting it breaks F18/F19 runs in the same stack.

  • Known issue #17710: On the Cloud backend, deleting a secret reportedly adds a suffixed duplicate and leaves the original. Reproduction needs a disposable writable OpenHands Cloud account at the affected service; Local secret CRUD exercises a different transport. (F14.delete, F14.edit).