[PR #141] fix: preserve custom env vars in multi-user mode via sudo -E #134

Open
opened 2026-10-18 21:11:06 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-terminal/pull/141
Author: @Blumlaut
Created: 7/21/2026
Status: 🔄 Open

Base: main ← Head: fix/preserve-env-multi-user-sudo


📝 Commits (1)

  • 169c237 fix: preserve custom env vars in multi-user mode via sudo -E

📊 Changes

1 file changed (+4 additions, -1 deletions)

View changed files

📝 open_terminal/utils/runner.py (+4 -1)

📄 Description

Problem

In multi-user mode (OPEN_TERMINAL_MULTI_USER=true), custom environment variables passed via the env field in POST /execute are silently dropped.

PtyRunner wraps commands with sudo -u <user> -- bash -c "...", but sudo resets the environment by default for security. The env dict is passed to subprocess.Popen, but never reaches the actual subprocess.

This breaks any workflow that relies on injecting env vars (e.g. GH_TOKEN for GitHub CLI authentication, API keys, custom config).

Solution

Add -E flag to sudo to preserve the environment through the user switch.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-terminal/pull/141 **Author:** [@Blumlaut](https://github.com/Blumlaut) **Created:** 7/21/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/preserve-env-multi-user-sudo` --- ### 📝 Commits (1) - [`169c237`](https://github.com/open-webui/open-terminal/commit/169c237c425021afdfb7e7252bc0b1d5b6418f29) fix: preserve custom env vars in multi-user mode via sudo -E ### 📊 Changes **1 file changed** (+4 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `open_terminal/utils/runner.py` (+4 -1) </details> ### 📄 Description ## Problem In multi-user mode (`OPEN_TERMINAL_MULTI_USER=true`), custom environment variables passed via the `env` field in `POST /execute` are silently dropped. `PtyRunner` wraps commands with `sudo -u <user> -- bash -c "..."`, but `sudo` resets the environment by default for security. The `env` dict is passed to `subprocess.Popen`, but never reaches the actual subprocess. This breaks any workflow that relies on injecting env vars (e.g. `GH_TOKEN` for GitHub CLI authentication, API keys, custom config). ## Solution Add `-E` flag to `sudo` to preserve the environment through the user switch. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
open-webui/open-terminal#134
No description provided.