Skip to content

fix(computer): stop shell inheriting deployment environment - #68

Merged
davidmckayv merged 11 commits into
CopilotKit:mainfrom
jeonjw85:stop-shell-inheriting-deployment-env
Aug 21, 2026
Merged

fix(computer): stop shell inheriting deployment environment#68
davidmckayv merged 11 commits into
CopilotKit:mainfrom
jeonjw85:stop-shell-inheriting-deployment-env

Conversation

@jeonjw85

@jeonjw85 jeonjw85 commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

What this changes

computer_run_command spawned with the computer process's own environment:

env: { ...process.env, HOME: workspaceDir },

What that inherits depends on how the deployment is run. Under Compose, agent-computer is handed COMPUTER_TOKEN. Under the one-container image the docs lead with, the computer starts via with-contenv, so it holds the container's environment, and that container is run --env-file .env. env is then a one-word command that returns KEY_ENCRYPTION_KEY, DATABASE_URL, OPENAI_API_KEY, INTELLIGENCE_API_KEY, COPILOTKIT_LICENSE_TOKEN, COMPUTER_TOKEN, SUPERVISOR_TOKEN, AGENT_TOOL_TOKEN. The trail records the command text and deliberately not its output, so the row this leaves reads like any other command.

A deny list is the secrets that existed on the day it was written. The next variable added to a deployment is not on it.

The shell now receives an allow list: PATH, locale and terminal names, and the proxy variables. A command that cannot find apt-get, cannot speak the operator's language, or cannot reach the network behind a corporate proxy is not a shell. HOME is still the workspace. Anything else is named in COMPUTER_SHELL_ENV, comma-separated, read as names — so JAVA_HOME,GOPATH passes those two, and KEY_ENCRYPTION_KEY;rm is not a name and is not read as one. Naming a secret there is an operator's decision rather than the default.

The larger question — shell off unless a supervisor is configured, or refusing EMBEDDED_POSTGRES and a shell at boot — is left alone. Scrubbing the environment is a floor, not the container boundary; root in a shared container can still read another process's environment. That is #66's second half.

Closes #66

Where it runs

  • New state that outlives a request? None. The map is built per spawn from the process environment and discarded with the child.
  • What happens on the second replica? Identical. Nothing is held; each computer process filters its own environment the same way.
  • Anything serialised? N/A, no writes.
  • Anything fanned out to a browser? No.
  • New listener, port, or schedule? No.

Boundary and audit

  • No change to the gateway's resolve, decide, audit, act order. The computer still does not decide whether a command may run.
  • The trail still records the command text and not its output. A leaked secret would not have shown up there anyway; the point of the allow list is that env in the workspace no longer prints it.

Changelog

  • Unreleased, Fixed: a Bot's shell no longer inherits the deployment's environment. COMPUTER_SHELL_ENV names extras.

Proof

Nine tests in agent-computer/tests/shell.test.ts.

The map a spawn would receive:

  • PATH, LANG/LC_ALL, TERM, and the proxy variables pass
  • KEY_ENCRYPTION_KEY, DATABASE_URL, OPENAI_API_KEY, COMPUTER_TOKEN, INTELLIGENCE_API_KEY do not, and their values are not present as strings either
  • HOME is the workspace, including when COMPUTER_SHELL_ENV names HOME
  • COMPUTER_SHELL_ENV=JAVA_HOME, GOPATH copies those two and not itself
  • naming KEY_ENCRYPTION_KEY in COMPUTER_SHELL_ENV copies it and still not OPENAI_API_KEY
  • KEY_ENCRYPTION_KEY;rm and FOO=bar are not names and are not copied

The command that actually runs, against a real /bin/bash -lc:

  • printenv in the child does not list KEY_ENCRYPTION_KEY or its value
  • printenv JAVA_HOME returns the value named in COMPUTER_SHELL_ENV

bash -lc is a login shell and rewrites PATH from the profile; the unit test still locks that PATH is in the map we hand spawn. The spawn tests lock the leak, which is the thing a helper-only test would miss if createShell went back to spreading process.env.

biome format and biome lint clean on shell.ts and shell.test.ts. 9 pass, 0 fail.

jeonjw85 and others added 5 commits August 21, 2026 10:44
apt-get reads DEBIAN_FRONTEND, and the shell tool description tells the model to
run it. Interactive, the install stops for an answer nobody is there to give:
the command reaches its timeout and comes back looking like a broken package
rather than a question.

Set rather than copied, because the deployment has no opinion about it and the
command does. An operator who wants a different frontend can still name it in
COMPUTER_SHELL_ENV, which is copied first.
@jeonjw85
jeonjw85 force-pushed the stop-shell-inheriting-deployment-env branch from 2039f6a to 5156bdb Compare August 21, 2026 01:44
@jeonjw85 jeonjw85 changed the title Stop the shell inheriting the deployment's environment fix(computer): stop shell inheriting deployment environment Aug 21, 2026
@davidmckayv

Copy link
Copy Markdown
Contributor

Reviewed this closely. The environment fix itself is correct and complete, and the allow-list is the right shape — the reasoning in the docstring about a deny-list being "the secrets that existed on the day it was written" is exactly right.

I checked the surface rather than just the diff: agent-computer has exactly one spawn, at shell.ts:157, so the shell is the only path where a Bot's input reaches a child process. Nothing else needed changing. The production call site passes no sourceEnv, so it takes the process.env default and gets filtered. Verified: 756 pass / 0 fail, typecheck and biome clean.

I also pushed one commit here — DEBIAN_FRONTEND=noninteractive, which this was missing. apt-get is what the tool description tells the model to run, and interactively it waits for an answer nobody is there to give, so the command hits its timeout and comes back looking like a broken package rather than a question. It's set rather than copied, and an operator can still override it via COMPUTER_SHELL_ENV.

Two things I'd want resolved.

1. The proxy variables can carry credentials — this one is introduced here

HTTP_PROXY and HTTPS_PROXY are copied into the command's environment. Credentials in a proxy URL are normal, and this repo's own .env.example:176 documents that exact form:

# EGRESS_PROXY_DEFAULT=http://user:password@proxy.internal:8080

EGRESS_PROXY_* is a different variable, so this is not automatic. But a deployment behind a corporate proxy sets HTTP_PROXY too, and would write it the same way. Then a Bot's shell reads the proxy username and password — which is the class of leak this PR exists to close, coming back through the allow-list.

Copying the proxy is still right; a command that cannot reach the network is not a shell. The question is whether to strip userinfo from the URL before passing it, or to document that a credentialed proxy is visible to a Bot and should be granted deliberately through COMPUTER_SHELL_ENV instead.

2. bash -lc still lets a Bot rewrite what a later command does — pre-existing, not from this PR

-l makes it a login shell, so it sources $HOME/.bash_profile, and HOME is the workspace the Bot can write with computer_write_file. The allow-list means that file can no longer recover a secret, so this PR does not make it worse. But it is still live, and the audit consequence is the bad part.

Run against this branch's code:

audited command: apt-get --version
actual output:   "[.bash_profile ran]\n[hijacked apt-get]"

The Bot wrote .bash_profile and a fake apt-get on the PATH it exported. The trail records apt-get --version. A shell being permissive is a decision you can make; a trail that says the wrong thing is not. -c instead of -l -c closes it, or HOME stops pointing at a Bot-writable directory.

Happy to do either of these as a follow-up if you'd rather keep this PR to the one change.

Verification carried over

I had opened #69 for the same fix and closed it in favour of this one. Its verification applies here, driven through the Bot on a running deployment rather than only unit tested — same conversation, same command, before and after:

before:  COMPUTER_TOKEN HOME HOSTNAME LANG LC_ALL PATH PLAYWRIGHT_BROWSERS_PATH PORT PWD SHLVL WORKSPACE_DIR _
after:   DEBIAN_FRONTEND HOME LANG LC_ALL PATH PWD SHLVL _

Worth knowing for anyone testing this: the deployment talks to the shared computer at AGENT_COMPUTER_URL, so the container has to be rebuilt before the fix is in the path at all. My first run still leaked for that reason, and a green unit test would have read as done.

Smaller notes

  • LOCALE_CATEGORY copies any LC_* from the parent by pattern. Low risk, but it is a wildcard inside an allow-list, which slightly softens the principle the docstring sets out.
  • extraShellEnvNames silently drops a name that fails ENV_NAME. An operator typo becomes a variable that is quietly absent, and the command fails somewhere else for a reason that does not mention the typo.

@jeonjw85

Copy link
Copy Markdown
Contributor Author

Addressed the proxy credentials.

Allow-listed HTTP_PROXY / HTTPS_PROXY (and the rest of that family) now have userinfo stripped before they reach the child, same split egress.ts already uses for the browser proxy. A command can still reach the network; env cannot print the password.

Naming the credentialed URL in COMPUTER_SHELL_ENV still passes it through — that is the operator's decision rather than the default.

Leaving bash -lc and HOME-as-workspace for a follow-up, as you offered. The LC_* wildcard and the silent drop of a bad COMPUTER_SHELL_ENV name too.

`-lc` made this a login shell, so it sourced $HOME/.bash_profile, and HOME is
the workspace a Bot writes with computer_write_file. A Bot could leave a file
that every later command ran first: put its own apt-get earlier on PATH, and the
audit row still read `apt-get --version`. Proven against this branch before the
change: the trail said `apt-get --version` and the output was
"[.bash_profile ran] [hijacked apt-get]".

The allow-list already means such a file cannot recover a secret. It could still
change what a command does, and a trail that describes something other than what
ran is worse than a shell that is too permissive, because nobody can tell.

`-c` reads no startup files but still expands BASH_ENV and runs what it names,
on bash 3.2 and 5.2 alike. Nothing but the allow-list closes that, so the test
asserts BASH_ENV is absent from the map rather than assuming it, along with the
option variables bash reads from its environment.
Two things stood between the shell and a release.

A deny rule naming a field the action does not have refused the action. The
context left out what an action had nothing to put in, cel-js throws on an
unknown identifier rather than treating it as absent, and a thrown deny counts as
a match so a mistyped deny refuses rather than quietly permitting. Each of those
is right on its own. Together, `deny: contains(command, "rm -rf")` — the example
in the docs — refused every click, keypress, navigation and file read in the
deployment. Proven before the change: that rule throws on a click context and the
click is refused; bound to a neutral value it evaluates false. Every field is now
bound. The audit row still omits what did not happen, because a trail should not
claim a click had a command.

The tests for this go through the gateway rather than handing the policy a
context written in the test. That is why this survived: a policy test asserting a
browser rule does not refuse a command passed, while production refused every
click, because the two contexts were different shapes.

And the transport gave every call one deadline, 45s, shorter than the shell's own
120s default and 600s maximum. The tool description tells the model to install a
package, so the person was told the computer had not responded while apt-get ran
to completion inside the container, and the shell's own limit was unreachable. A
command now carries a deadline that outlasts the shell, which reports the timeout
itself.
@Hotragn

Hotragn commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

I filed #66 and had a branch doing the same scrub; I have closed it, because this is the better change and it got here first. Two things in it I did not have: stripping userinfo out of the proxy URLs, and DEBIAN_FRONTEND. I had reasoned that one away because the image never sets it, which was the wrong question — the tool description tells the model to run apt-get install, so the prompt is reachable from the feature's own documentation.

The -lc catch is the part worth the most here, and I missed it entirely. A trail that names something other than what ran is a worse failure than the one I reported.

One suggestion, offered as something to make the allow list hold rather than a problem with it.

BASH_ENV is the same vector as .bash_profile and survives the fix to -c: bash reads it for non-interactive shells and sources whatever file it names, before the command. It is closed here, but closed incidentally — it is absent from the allow list, so nothing copies it. That is the kind of boundary that stops holding quietly. If somebody later adds a general "copy anything matching BASH_*" convenience, or an operator names it in COMPUTER_SHELL_ENV, the login-shell hole is back with -c still in place and the reasoning for -c sitting a few lines above, looking satisfied.

A test asserting BASH_ENV is not in the returned environment even when the source has one would pin it, in the same shape as the secrets test already here. ENV and BASH_XTRACEFD are the same family if you want them, though BASH_ENV is the one that executes a file.

Worth considering whether COMPUTER_SHELL_ENV should refuse those names outright rather than pass them, given it already refuses anything that is not a variable name. An operator naming GITHUB_TOKEN is making a decision about a secret; an operator naming BASH_ENV is handing a Bot a hook into every command it runs afterwards, which they are unlikely to have meant.

Six things, all of them reachable from the feature as documented.

Output was accumulated whole and trimmed only after close, so a command that
prints a few megabytes allocated until the process that owns the browser died.
Bounded as it arrives now, and the trim carries the fact that it happened: a
stream already cut arrives under the limit and would otherwise look complete,
which is worse than the allocation because a model reads it as the whole answer.

A stop signalled bash and nothing bash started. `sleep 30 | cat` left the
children holding the inherited pipes, so close never fired and the call waited
for something upstream to give up. The process group is signalled now.

A timeoutMs of zero passed Math.min and fired setTimeout immediately, killing the
command before it ran and reporting a timeout. It has a floor.

/exec never took the person's abort, so the plumbing through runCommand into the
shell's own listener was dead code and Stop left the command finishing.

The live-screen socket asked the provider for an address instead of the gateway,
skipping the check the gateway does, and then put COMPUTER_TOKEN in the query
string of whatever it was told. Every acting path already went through the
gateway; this one did not.

And COMPUTER_SHELL_ENV now refuses BASH_ENV, ENV, LD_PRELOAD and the option
variables. That setting is meant for an operator deciding a Bot may use a token.
These do not inform a command, they run before every later one, which is the
.bash_profile hole arriving by the front door with the reasoning for -c sitting a
few lines above looking satisfied. Refused loudly, and a name that is not a
variable name is reported now rather than silently dropped.
sudo was NOPASSWD: ALL. The comment above it was already clear about the cost,
and clear about what made it acceptable: a container that is one Bot's alone and
does not hold a database. This image is neither. The supervisor is deliberately
not in it, so every Bot shares one computer, and EMBEDDED_POSTGRES=on is a
documented way to run it. Root there reads another Bot's workspace, the API's
environment, and the audit database that records what it did.

Naming the commands keeps the feature and removes the rest. apt-get, apt, dpkg,
apt-key and apt-cache, which is what the tool description tells a model to run.
Verified in the built image: sudo apt-get works, sudo cat, sudo sh and sudo -i
are refused. The sudoers file is syntax-checked at build with visudo -cf, because
a malformed drop-in disables sudo entirely rather than failing loudly.

This is a floor, not a boundary. Root is one CVE away and a shared container is
not an isolation story for code a model wrote. The answers already exist here:
COMPUTER_SUPERVISOR_URL for a computer per Bot, COMPUTER_RUNTIME=runsc to put
gVisor under it. What is missing is that the single-container image cannot reach
either, which is worth saying rather than implying the narrowed grant settles it.
@davidmckayv
davidmckayv merged commit 5eb35ae into CopilotKit:main Aug 21, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A Bot's shell is handed the deployment's environment, including the key that decrypts stored credentials

3 participants