Agent runs "sudo" and freezes UI when analyzing system configs (e.g. Apache) #2126

Open
opened 2026-02-16 17:34:17 -05:00 by yindo · 5 comments
Owner

Originally created by @RaphGod on GitHub (Oct 16, 2025).

Originally assigned to: @thdxr on GitHub.

What happens:
When I ask the agent something like “analyse the Apache config please”, it automatically tries to read files under /etc/apache2/ and runs a sudo command (for example sudo cat /etc/apache2/sites-enabled/...).
If the user has no sudo access, the process waits for a password prompt and the whole interface freezes — you have to hard-reset or close the terminal. (esc or Ctrl +C don't work).

Important:
This is not a security issue. The user has no sudo rights anyway. The real problem is that the interface becomes blocked, and this can happen very easily — especially:

when someone clicks “OK” too quickly in plan mode, or when a build runs automatically without supervision.

Environment:
OpenCode version: opencode v0.11.3
OS: Ubuntu 22.04
Agent : Plan claude-sonnet-4-5
User: non-sudo

Steps to reproduce:
Use a non-sudo account.
In a session, type: analyse the Apache config or similar.
The agent tries sudo cat /etc/apache2/....
Terminal freezes waiting for password.

Actual behaviour:
CLI/UI hangs indefinitely.
No keyboard control.
Must kill process or reset the terminal.
when I comeback in the session => the work going to the whereas the UI was brocken.

Expected behaviour:
The agent should detect forbidden commands (like sudo, su) before running anything.
It should fail fast and show a message instead of hanging.
This behaviour should be persistent and configurable.

Possible config example:
{
"agent": {
"allow_sudo": false,
"forbidden_commands": ["sudo", "su"],
"command_execution": {
"fail_fast_on_forbidden": true
}
}
}

Example error message:
Refused to execute command: contains forbidden token "sudo". To override, set agent.allow_sudo=true in config

Why this matters:
It can happen by accident during plan/build, especially when confirming too fast in plan.
The problem is usability, not security.

A simple pre-check would prevent interface freezes and lost sessions.

Extrat Past of screan with !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! where it crashed.

┃ Shell Check cron jobs ┃
┃ ┃
┃ $ crontab -l 2>/dev/null | grep -i xxxxx || echo "No cron jobs for xxxxx" ┃
┃ No cron jobs for xxxxx ┃
┃ ┃

┃ ┃
┃ Shell Read Apache config with sudo ┃
┃ ┃
┃ $ sudo cat /etc/apache2/sites-available/xxxxx.com.conf ┃
┃ sudo: 3 incorrect password attempts ┃
===>>>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Here it crashed but as you can see the task was cotinued in another dimension ;-)
┃ ┃

┃ ┃
┃ Shell Read systemd API service ┃
┃ ┃
┃ $ sudo cat /etc/systemd/system/xxxxx-prod-api.service ┃
┃ ┃

┃ ┃
┃ Shell Read systemd frontend service ┃
┃ ┃
┃ $ sudo cat /etc/systemd/system/xxxxx-prod-frontend.service ┃
┃ ┃

┃ ┃
┃ Read xxxxx-prod-api.service ┃
┃ ┃
┃ [Unit] ┃
┃ Description=xxxxx Production API ┃
┃ After=network.target mariadb.service

📝 AMÉLIORATION DU SCRIPT BACKUP (backup_xxxxx_work.sh)

 Ajouts nécessaires :                                                                                                                                          
                                                                                                                                                               
 1. Step de confirmation :                                                                                                                                     
                                                                                                                                                               
 echo "🔄 Backup xxxxx complet"                                                                                                                             
 echo "📊 3 bases MySQL + code + configs système"                                                                                                              
 read -p "Continuer? (y/n) " -n 1 -r                                                                                                                           
 [[ ! $REPLY =~ ^[Yy]$ ]] && exit 0                                                                                                                            
                                                                                                                                                               
 2. Sauvegarder configs Apache :                                                                                                                               
                                                                                                                                                               
 # Apache configs                                                                                                                                              
 mkdir -p "$TEMP_DIR/apache"                                                                                                                                   
 cp /etc/apache2/sites-available/xxxxx.com.conf "$TEMP_DIR/apache/" 2>/dev/null                                                                             
                                                                                                                                                               
 3. Sauvegarder Logrotate :                                                                                                                                    
                                                                                                                                                               
 # Logrotate                                                                                                                                                   
 cp /etc/logrotate.d/xxxxx-logrotate "$TEMP_DIR/" 2>/dev/null                                                                                               
                                                                                                                                                               
 4. **Sauve                                                                                                                                                    
 Plan claude-sonnet-4-5-20250929 (12:25 PM)                                                                                                                    

┃ ┃
┃ Request was aborted

opencode v0.11.3 ~/apps/xxxxx:dev

Originally created by @RaphGod on GitHub (Oct 16, 2025). Originally assigned to: @thdxr on GitHub. What happens: When I ask the agent something like “analyse the Apache config please”, it automatically tries to read files under /etc/apache2/ and runs a sudo command (for example sudo cat /etc/apache2/sites-enabled/...). If the user has no sudo access, the process waits for a password prompt and the whole interface freezes — you have to hard-reset or close the terminal. (esc or Ctrl +C don't work). Important: This is not a security issue. The user has no sudo rights anyway. The real problem is that the interface becomes blocked, and this can happen very easily — especially: when someone clicks “OK” too quickly in plan mode, or when a build runs automatically without supervision. Environment: OpenCode version: opencode v0.11.3 OS: Ubuntu 22.04 Agent : Plan claude-sonnet-4-5 User: non-sudo Steps to reproduce: Use a non-sudo account. In a session, type: analyse the Apache config or similar. The agent tries sudo cat /etc/apache2/.... Terminal freezes waiting for password. Actual behaviour: CLI/UI hangs indefinitely. No keyboard control. Must kill process or reset the terminal. when I comeback in the session => the work going to the whereas the UI was brocken. Expected behaviour: The agent should detect forbidden commands (like sudo, su) before running anything. It should fail fast and show a message instead of hanging. This behaviour should be persistent and configurable. Possible config example: { "agent": { "allow_sudo": false, "forbidden_commands": ["sudo", "su"], "command_execution": { "fail_fast_on_forbidden": true } } } Example error message: Refused to execute command: contains forbidden token "sudo". To override, set agent.allow_sudo=true in config Why this matters: It can happen by accident during plan/build, especially when confirming too fast in plan. The problem is usability, not security. A simple pre-check would prevent interface freezes and lost sessions. Extrat Past of screan with !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! where it crashed. ┃ ┃ Shell Check cron jobs ┃ ┃ ┃ ┃ $ crontab -l 2>/dev/null | grep -i xxxxx || echo "No cron jobs for xxxxx" ┃ ┃ No cron jobs for xxxxx ┃ ┃ ┃ ┃ ┃ ┃ Shell Read Apache config with sudo ┃ ┃ ┃ ┃ $ sudo cat /etc/apache2/sites-available/xxxxx.com.conf ┃ ┃ sudo: 3 incorrect password attempts ┃ ===>>>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Here it crashed but as you can see the task was cotinued in another dimension ;-) ┃ ┃ ┃ ┃ ┃ Shell Read systemd API service ┃ ┃ ┃ ┃ $ sudo cat /etc/systemd/system/xxxxx-prod-api.service ┃ ┃ ┃ ┃ ┃ ┃ Shell Read systemd frontend service ┃ ┃ ┃ ┃ $ sudo cat /etc/systemd/system/xxxxx-prod-frontend.service ┃ ┃ ┃ ┃ ┃ ┃ Read xxxxx-prod-api.service ┃ ┃ ┃ ┃ [Unit] ┃ ┃ Description=xxxxx Production API ┃ ┃ After=network.target mariadb.service ## 📝 AMÉLIORATION DU SCRIPT BACKUP (backup_xxxxx_work.sh) Ajouts nécessaires : 1. Step de confirmation : echo "🔄 Backup xxxxx complet" echo "📊 3 bases MySQL + code + configs système" read -p "Continuer? (y/n) " -n 1 -r [[ ! $REPLY =~ ^[Yy]$ ]] && exit 0 2. Sauvegarder configs Apache : # Apache configs mkdir -p "$TEMP_DIR/apache" cp /etc/apache2/sites-available/xxxxx.com.conf "$TEMP_DIR/apache/" 2>/dev/null 3. Sauvegarder Logrotate : # Logrotate cp /etc/logrotate.d/xxxxx-logrotate "$TEMP_DIR/" 2>/dev/null 4. **Sauve Plan claude-sonnet-4-5-20250929 (12:25 PM) ┃ ┃ ┃ Request was aborted opencode v0.11.3 ~/apps/xxxxx:dev
Author
Owner

@github-actions[bot] commented on GitHub (Oct 16, 2025):

This issue might be a duplicate of existing issues. Please check:

  • #3154: Reports that commands (like Prisma) can lock opencode indefinitely, similar to the sudo hanging behavior described here
  • #3027: Terminal gets corrupted when prompted for SSH key - describes similar UI freezing when interactive authentication prompts appear

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Oct 16, 2025): This issue might be a duplicate of existing issues. Please check: - #3154: Reports that commands (like Prisma) can lock opencode indefinitely, similar to the sudo hanging behavior described here - #3027: Terminal gets corrupted when prompted for SSH key - describes similar UI freezing when interactive authentication prompts appear Feel free to ignore if none of these address your specific case.
Author
Owner

@veracioux commented on GitHub (Oct 16, 2025):

You can configure the following:

"permission": {
  "bash": {
    "sudo *": "deny"
  }
}

Reference: https://opencode.ai/docs/permissions/#wildcards

@veracioux commented on GitHub (Oct 16, 2025): You can configure the following: ```json "permission": { "bash": { "sudo *": "deny" } } ``` Reference: https://opencode.ai/docs/permissions/#wildcards
Author
Owner

@rekram1-node commented on GitHub (Oct 16, 2025):

Yeah I would recommend doing this ^, eventually we may be able to do some cool stuff with opentui to let you actually handle the interactive shell things like sudo, but for now I recommend using permissions like @veracioux suggested.

@rekram1-node commented on GitHub (Oct 16, 2025): Yeah I would recommend doing this ^, eventually we may be able to do some cool stuff with opentui to let you actually handle the interactive shell things like sudo, but for now I recommend using permissions like @veracioux suggested.
Author
Owner

@veracioux commented on GitHub (Oct 16, 2025):

@rekram1-node Small note about sudo specifically: Sudo caches credentials (per pty session AFAIK), so a prudent handling would probably involve enforcing sudo -k instead of just sudo.

@veracioux commented on GitHub (Oct 16, 2025): @rekram1-node Small note about `sudo` specifically: Sudo caches credentials (per pty session AFAIK), so a prudent handling would probably involve enforcing `sudo -k` instead of just `sudo`.
Author
Owner

@zeekhuge commented on GitHub (Jan 31, 2026):

You can set the environment variable SSH_ASKPASS=/usr/bin/ssh-askpass while starting opencode:

$ SSH_ASKPASS=/usr/bin/ssh-askpass opencode

This will automatically open a GUI window for you to enter the sudo password, whenever the sudo command gets executed.

More info: https://unix.stackexchange.com/questions/83986/tell-ssh-to-use-a-graphical-prompt-for-key-passphrase

@zeekhuge commented on GitHub (Jan 31, 2026): You can set the environment variable `SSH_ASKPASS=/usr/bin/ssh-askpass` while starting opencode: ```bash $ SSH_ASKPASS=/usr/bin/ssh-askpass opencode ``` This will automatically open a GUI window for you to enter the sudo password, whenever the sudo command gets executed. More info: https://unix.stackexchange.com/questions/83986/tell-ssh-to-use-a-graphical-prompt-for-key-passphrase
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#2126