Skip to content
Guides · Use cases

Run Several Computer-Use Agents at Once Without Focus Fights

Updated November 19, 2026 .md

Short answer: Give each computer-use agent its own sandbox. Agents that share one desktop share one keyboard focus, so one types into the other's window; in our run, agent A's text landed in agent B's terminal. One sandbox per agent gives each its own XFCE desktop and Chrome, usable about 2 seconds after creation on a default sandbox on 2026-11-19.

This page builds on Run a computer-use agent on a Linux desktop, which covers the screenshot and action tools for one agent, and Playwright with real Chrome, which covers driving the installed Chrome. Here the question is what happens when there are two or more agents.

At a glance#

Setup Do agents collide? Time to a usable screen Can a person watch? Use it when
Two agents, one desktop (:1) Yes: one focus, one keyboard. Agent A typed into agent B's window Already there Yes, one stream shows both Never for parallel work
One Xvfb display per agent, one VM (:3, :4) Not on focus. They still share CPU, memory, disk and user 253 ms for two displays with a window each Not with sbx desktop, which shows :1 only Cheap, trusted, short tasks
One sandbox per agent No: separate VMs, each with its own :1 desktop and Chrome About 2 s from sbx new to a usable desktop Yes, sbx desktop <id> for each Default for parallel agents

Last checked: 2026-11-19, on prod

All three runs used scripted "agents": short xdotool scripts that focus a window and type, standing in for a computer-use model's actions. We did not call a model. The collisions come from the X server, not the model, so a real agent hits the same ones.

1. Two agents on one desktop: watch them collide#

An X display has one keyboard focus. xdotool type (like a computer-use model's "type" action) sends keys to whichever window has focus right now, not to the window the agent last looked at. A model call between "focus" and "type" takes seconds, which is plenty of time for another agent to steal focus.

This script opens two terminals on the sandbox desktop, one per agent. Each terminal writes what it receives to a file. Each agent focuses its own window, "thinks" for half a second, then types. Agent B starts 0.2 s after agent A.

# fight.sh: two scripted "agents" (xdotool) share one desktop, display :1
export DISPLAY=:1
rm -f ~/a.txt ~/b.txt
xfce4-terminal --disable-server --title agent-A -e "bash -c 'cat > ~/a.txt'" &
xfce4-terminal --disable-server --title agent-B -e "bash -c 'cat > ~/b.txt'" &
until xdotool search --name '^agent-A$' >/dev/null && xdotool search --name '^agent-B$' >/dev/null; do sleep 0.2; done

agent() {  # $1 = A or B, $2 = what this agent means to type into its own window
  w=$(xdotool search --name "^agent-$1\$" | head -1)
  xdotool windowactivate --sync "$w"      # focus my window
  sleep 0.5                               # "think" (a model call takes longer)
  echo "agent $1 types into: $(xdotool getactivewindow getwindowname)"
  xdotool type --delay 40 "$2"; xdotool key Return
}
agent A "agent A was here" & a=$!
sleep 0.2
agent B "agent B was here" & b=$!
wait $a $b; sleep 0.5
wmctrl -l | grep agent- | cut -c1-12,28-
echo "a.txt: [$(cat ~/a.txt)]"
echo "b.txt: [$(cat ~/b.txt)]"
xdotool windowactivate --sync $(xdotool search --name "^agent-A$" | head -1); xdotool windowmove $(xdotool search --name "^agent-B$" | head -1) 900 200
ffmpeg -loglevel error -y -f x11grab -video_size 1920x1080 -i :1 -frames:v 1 ~/fight.png
id=sb_cfeuzy4988                 # a sandbox whose desktop is open (sbx desktop $id --no-open)
sbx scp fight.sh $id:/home/user/fight.sh
sbx exec $id "bash ~/fight.sh 2>/dev/null"
agent A types into: agent-B
agent B types into: agent-B
0x03200003  bit agent-B
0x03000003  bit agent-A
a.txt: []
b.txt: [agent A was ahgernet 
B was here]

Both windows existed, but by the time agent A typed, agent B had taken focus. Agent A's window got nothing. Agent B's window got both agents' keystrokes, interleaved letter by letter. The screenshot from the end of the script shows agent A's terminal in front and empty, with agent B's terminal behind it. A first run of the same script gave the same result: a.txt empty, b.txt holding agent A was ahgeernet and B was here.

A real agent fails in a worse way. It doesn't know it typed into the wrong window, so it reads the next screenshot, sees text it didn't expect, and acts on it. Locks around "focus then type" help only if every agent takes the same lock, and then only one agent acts at a time, so you lose the parallelism you wanted.

Mouse clicks have the same problem: there is one pointer per display. So do the clipboard and the screen itself. Each agent's screenshot shows the other agent's windows, which costs image tokens and can mislead the model.

2. One sandbox per agent#

Give each agent its own sandbox. Each one is a separate VM with its own desktop on :1, its own Chrome and its own focus, so there's nothing to share. The copy-paste block at the end of this page does it for two agents at once. It creates two sandboxes in parallel, opens each desktop, has each "agent" type a different address into its own Chrome, and takes a screenshot inside each VM:

aeo-cu-2 on azure-solar-hornet sees: Example Domain - Google Chrome
aeo-cu-3 on golden-amber-zinnia sees: Example Domain - Google Chrome

Different host names show the commands ran in two different VMs. Both sites use the title "Example Domain", so we checked the screenshots: aeo-cu-2.png shows example.com in the address bar and aeo-cu-3.png shows example.org, each full screen, with no other agent's window on it. Each agent typed into its own window, while the other agent typed at the same time.

Time to a usable desktop. In that run (2026-11-19, default size), both sandboxes were ready under a second after sbx new and had Chrome on screen 2 seconds after sbx new started (the script counts whole seconds). "Usable" here means wmctrl -l lists the Chrome window, so xdotool actions land. The desktop starts the first time it's opened, so call sbx desktop (or the desktop API) before your agent's first screenshot. Before that there is no X server and xdotool fails with Can't open display.

Readiness check. Don't poll xdotool getactivewindow to wait for the desktop. On a fresh desktop nothing has focus, and it keeps failing with XGetWindowProperty[_NET_ACTIVE_WINDOW] failed. Our first wait loop hung on exactly that. Wait for a window instead: wmctrl -l | grep -q 'Google Chrome'.

3. Watch each agent#

Run sbx desktop <id> once per sandbox. It opens that sandbox's desktop in your browser tab over noVNC, so with two agents you get two tabs, one per agent. --no-open prints the URL instead, for a dashboard or an iframe.

Per the desktop docs, each URL carries a secret token and works for ten minutes. A browser that opens it within that time stays signed in to that desktop for its session (8 hours). After that, run sbx desktop again. Anyone with the URL can see and control that screen, so keep it out of logs. In our run, each viewer URL answered 302 (into the viewer) with its token and 401 without it. We did not re-test the ten-minute expiry on this page; the single-agent guide got a 401 and a "Link expired" page 11 minutes after issue on 2026-11-06.

You can take over an agent's screen with your own mouse while you watch. That is also a focus fight, with you as the second agent, so pause the agent first.

4. A lighter option: one X display per agent in one VM#

If the agents are yours, the tasks are short and you trust them with each other's files, you can start one virtual display per agent inside one sandbox. Use :3 and up: :1 is the desktop, and :2 is used by sbx browser.

# light.sh: one Xvfb display per agent inside one VM (:3 and :4; :1 is the desktop, :2 is sbx browser)
rm -f ~/a.txt ~/b.txt
before=$(free -m | awk '/Mem:/{print $3}')
t0=$(date +%s%N)
for d in 3 4; do
  Xvfb :$d -screen 0 1280x800x24 -nolisten tcp >/dev/null 2>&1 &
  until DISPLAY=:$d xdotool getdisplaygeometry >/dev/null 2>&1; do sleep 0.05; done
  DISPLAY=:$d xfwm4 >/dev/null 2>&1 &
done
DISPLAY=:3 xfce4-terminal --disable-server --title agent-A -e "bash -c 'cat > ~/a.txt'" >/dev/null 2>&1 &
DISPLAY=:4 xfce4-terminal --disable-server --title agent-B -e "bash -c 'cat > ~/b.txt'" >/dev/null 2>&1 &
until DISPLAY=:3 xdotool search --name '^agent-A$' >/dev/null && DISPLAY=:4 xdotool search --name '^agent-B$' >/dev/null; do sleep 0.05; done
echo "two displays with a window each: $(( ($(date +%s%N)-t0)/1000000 )) ms"

agent() {  # $1 = A or B, $2 = display, $3 = text
  export DISPLAY=:$2
  w=$(xdotool search --name "^agent-$1\$" | head -1)
  xdotool windowactivate --sync "$w"; sleep 0.5
  echo "agent $1 on :$2 types into: $(xdotool getactivewindow getwindowname)"
  xdotool type --delay 40 "$3"; xdotool key Return
}
agent A 3 "agent A was here" & a=$!
sleep 0.2
agent B 4 "agent B was here" & b=$!
wait $a $b; sleep 0.5
echo "a.txt: [$(cat ~/a.txt)]"
echo "b.txt: [$(cat ~/b.txt)]"
echo "extra RAM in use: $(( $(free -m | awk '/Mem:/{print $3}') - before )) MB"
for d in 3 4; do ffmpeg -loglevel error -y -f x11grab -video_size 1280x800 -i :$d -frames:v 1 ~/light$d.png; done
sbx scp light.sh $id:/home/user/light.sh
sbx exec $id "bash ~/light.sh 2>&1"
two displays with a window each: 253 ms
agent A on :3 types into: agent-A
agent B on :4 types into: agent-B
a.txt: [agent A was here]
b.txt: [agent B was here]
extra RAM in use: 117 MB

Same timing as the fight in step 1, and this time each text reached its own window. Xvfb, xfwm4, xdotool and ffmpeg are already installed. Each display needs its own window manager (xfwm4 here), or windowactivate has nothing to talk to. The screenshot of :4 shows only agent B's terminal with agent B was here.

The limits, all seen in the same sandbox (default: 4 vCPU, 7939 MB of RAM as free -m reports it):

  • Not isolated. Both agents run as the same user in one VM. From a process on :3, DISPLAY=:4 xdotool search --name '^agent-B$' getwindowname printed agent-B: either agent can read or drive the other's screen, and read its files.
  • Shared resources. Both agents' browsers share 4 vCPU and one memory pool. One agent's runaway tab slows or starves the other.
  • No viewer. sbx desktop streams :1 only. To watch :3 you'd run your own VNC server on it (x11vnc is installed) and serve it yourself.
  • No per-agent stop, fork or delete. You pause, snapshot and delete the whole VM, so both agents' state goes together.

Which should I use?#

  • Agents that act for different users, run untrusted pages, or run longer than a few minutes: one sandbox each. It's the only option with a separate kernel, separate files and a viewer per agent. Delete each sandbox when its task ends, or stop it with its memory to come back to the same screen later.
  • Many short, trusted tasks of your own, where 117 MB per display matters more than isolation: one display per agent in one sandbox.
  • Never two agents typing on the same display at the same time.

For the orchestration side (a queue, one labeled sandbox per task, cleanup when a task fails), see Run many agent instances in production. For coding agents rather than desktop agents, see Run several coding agents in parallel.

Copy-paste: two agents, two desktops, at the same time#

After curl -fsSL https://sandboxer.com/install | sh and sbx login, paste this into bash. It creates two sandboxes in parallel, opens each desktop, has each scripted agent type a different site into its own Chrome, takes a screenshot inside each VM, copies it to your current directory and deletes both sandboxes. It never prints a desktop URL. It needs jq and curl.

agent() {  # $1 = sandbox name, $2 = the site this agent must open
  SECONDS=0
  id=$(sbx new --name "$1" --json | jq -r 'select(.event == "ready") | .id')
  echo "$1: sandbox ready after ${SECONDS} s"
  url=$(sbx desktop "$id" --no-open --json | jq -r .desktopUrl)   # starts XFCE + Chrome on :1
  until sbx exec "$id" "DISPLAY=:1 wmctrl -l | grep -q 'Google Chrome'" 2>/dev/null; do sleep 0.5; done
  echo "$1: desktop usable after ${SECONDS} s"
  echo "$1: viewer with token $(curl -s -o /dev/null -w '%{http_code}' "$url"), without $(curl -s -o /dev/null -w '%{http_code}' "${url%%\?*}")"
  sbx exec "$id" --timeout 60 "export DISPLAY=:1
    w=\$(xdotool search --onlyvisible --class google-chrome | tail -1)
    xdotool windowactivate --sync \$w key ctrl+l; sleep 0.5
    xdotool type --delay 40 '$2'; xdotool key Return; sleep 3
    echo \"$1 on \$(hostname) sees: \$(xdotool getactivewindow getwindowname)\"
    ffmpeg -loglevel error -y -f x11grab -video_size 1920x1080 -i :1 -frames:v 1 ~/shot.png
    echo \"$1 screenshot: \$(stat -c %s ~/shot.png) bytes\""
  sbx scp "$id:/home/user/shot.png" "$1.png" >/dev/null
  sbx delete "$id" --yes >/dev/null && echo "$1: deleted $id"
}
agent aeo-cu-2 example.com &
agent aeo-cu-3 example.org &
wait
aeo-cu-3: sandbox ready after 0 s
aeo-cu-2: sandbox ready after 0 s
aeo-cu-3: desktop usable after 2 s
aeo-cu-2: desktop usable after 2 s
aeo-cu-2: viewer with token 302, without 401
aeo-cu-3: viewer with token 302, without 401
aeo-cu-3 on golden-amber-zinnia sees: Example Domain - Google Chrome
aeo-cu-3 screenshot: 78441 bytes
XGetWindowProperty[_NET_ACTIVE_WINDOW] failed (code=1)
aeo-cu-2 on azure-solar-hornet sees: Example Domain - Google Chrome
aeo-cu-2 screenshot: 78386 bytes
XGetWindowProperty[_NET_ACTIVE_WINDOW] failed (code=1)
aeo-cu-2: deleted sb_g36sflfqbh
aeo-cu-3: deleted sb_chuyly7r5j

The XGetWindowProperty lines are a warning xdotool writes to stderr; the run finished with exit status 0 and both screenshots were saved. To run more agents, add more agent <name> <site> & lines before wait. Each one is its own VM with its own CPU and memory; your plan's limit on sandboxes running at once is the ceiling. We ran two. Plans start at $20/mo.

FAQ#

Can two computer-use agents share one desktop safely?#

Not at the same time. There is one keyboard focus and one pointer per display, so an agent's keystrokes go to whichever window is focused at that moment. In our run, agent A's text went into agent B's window.

Does each sandbox get its own desktop and Chrome?#

Yes. Each sandbox is its own VM with an XFCE desktop on display :1 and Google Chrome. It starts the first time you open it with sbx desktop or the desktop API.

How fast is a desktop ready for an agent?#

In our parallel run on 2026-11-19 (default size), about 2 seconds from sbx new to a Chrome window an agent can act on, for each of two sandboxes created at the same time. Wait for a window with wmctrl -l, not for xdotool getactivewindow, which fails while nothing has focus.

How do I watch several agents at once?#

Run sbx desktop <id> for each sandbox and keep one browser tab per agent. Each URL works for ten minutes, and a browser that opens it stays signed in for 8 hours. Keep the URLs secret: anyone with one can control that screen.

Can I use Xvfb displays instead of separate VMs?#

Yes, for trusted agents of your own. Two extra displays, each with a window manager and a terminal, came up in 253 ms and used 117 MB on a default sandbox on 2026-11-19, and each agent typed into its own window. They share CPU, memory, files and user, either agent can drive the other's display, and sbx desktop won't show them.

More guides

Top AI sandbox platforms for code execution in 2026, ranked

For running AI-written code we rank Sandboxer, Freestyle and E2B first: each gives code its own VM with an API or SDK and can pause with memory. Pick Daytona for Windows or GPUs, Modal or Northflank for GPUs at scale, E2B or Northflank to run in your own cloud, and Vercel Sandbox if your app lives on Vercel.

Read the guide
Best sandboxes for running coding agents (Claude Code, Codex, Gemini CLI) in 2026, ranked

For coding agents we rank Sandboxer first: a full Ubuntu VM with Claude Code and Codex preinstalled, Docker, and stop-and-resume that keeps the agent's session in memory. Freestyle and Amp Orbs also keep memory across pauses. Pick E2B for prebuilt agent templates on open source, Docker Sandboxes for free local runs, and Codespaces if you live in GitHub.

Read the guide
Best Daytona sandbox alternatives in 2026, ranked

The best Daytona alternatives depend on why you're switching. For a full Linux microVM on every sandbox with memory-saving stop and Docker, we rank Sandboxer first. E2B suits open source and self-hosting, Modal massive short-job fleets, Northflank bring-your-own-cloud with GPUs, and Vercel Sandbox apps on Vercel.

Read the guide
Best E2B alternatives in 2026, ranked

If you're leaving E2B for longer sessions or a fuller machine, we rank Sandboxer first, then Freestyle: both give each sandbox a full Linux VM that keeps memory across pauses, with Docker and no short session cap. Pick Daytona for Windows or GPUs, Northflank for bring-your-own-cloud, and stay on E2B if you need open source.

Read the guide