Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(cua-sandbox): support local Linux on ARM64 (#3257)

r33drichardse4b0a03e739f
diff --git a/handoff.md b/handoff.md
new file mode 100644
index 0000000000..67ef0de633
--- /dev/null
+++ b/handoff.md
@@ -0,0 +1,104 @@
+# Apple Silicon Local Linux Docker E2E Handoff
+
+## Objective
+
+Validate `trycua/cua#3257` on a real Apple Silicon Mac using Docker Desktop. The run must prove that the ARM64 image starts through `cua-sandbox`, computer-server is reachable through Docker's published host port, desktop screenshots and clipboard operations work, and the ephemeral container is removed.
+
+Do not modify code, create commits, push branches, or change the pull request. Run the test and report evidence only.
+
+## Prerequisites
+
+- Apple Silicon Mac (`uname -m` returns `arm64`)
+- Docker Desktop running
+- `uv` installed
+- Local clone of `https://github.com/trycua/cua`
+- Branch `codex/cua-sandbox-arm64-linux`
+- Candidate Docker image tag or digest, if testing before `docker-latest` is published
+
+## Checkout
+
+```bash
+git fetch origin codex/cua-sandbox-arm64-linux
+git switch codex/cua-sandbox-arm64-linux
+git pull --ff-only origin codex/cua-sandbox-arm64-linux
+git status --short
+```
+
+Stop if the worktree is not clean.
+
+## Record Environment
+
+```bash
+uname -a
+uname -m
+docker version
+uv --version
+```
+
+## Candidate Image Run
+
+Use the immutable Docker image produced by `trycua/cloud#7099`. A local Docker tag is also accepted.
+
+```bash
+IMAGE='<candidate-image-tag-or-digest>'
+
+docker pull "$IMAGE" || docker image inspect "$IMAGE"
+
+docker image inspect "$IMAGE" \
+ --format 'repo_digests={{json .RepoDigests}} architecture={{.Architecture}} os={{.Os}}'
+
+./libs/python/cua-sandbox/scripts/live_local_linux_docker.py \
+ --image ""
+```
+
+Expected terminal result:
+
+```text
+PASS: local Linux Docker sandbox is healthy
+```
+
+## Published Default Run
+
+Run this only after `public.ecr.aws/k5j5w0x5/cua-ubuntu-24.04:docker-latest` exists. This verifies the image resolution shipped by `cua#3257` rather than an explicit override.
+
+```bash
+./libs/python/cua-sandbox/scripts/live_local_linux_docker.py
+```
+
+## Success Criteria
+
+The script must verify all of the following:
+
+- host architecture is Apple Silicon ARM64;
+- the Linux container reports `aarch64`;
+- computer-server accepts shell commands through the published Docker port;
+- screenshot is a valid PNG larger than 10 KB;
+- screen dimensions are positive;
+- clipboard write/read returns the exact marker;
+- the ephemeral Docker container is removed after exit.
+
+Artifacts are written to `/tmp/cua-linux-arm64-live`:
+
+- `summary.json`
+- `screenshot.png`
+- `docker-inspect.json` on failure
+- `docker.log` on failure
+
+## Failure Report
+
+Return:
+
+1. Full command output.
+2. `/tmp/cua-linux-arm64-live/summary.json`.
+3. `/tmp/cua-linux-arm64-live/docker.log`, if present.
+4. `/tmp/cua-linux-arm64-live/docker-inspect.json`, if present.
+5. Output from:
+
+```bash
+docker ps -a --filter label=cua.sandbox=true
+docker images --digests | grep -E 'cua-ubuntu|cua-xfce|xfce-cua' || true
+git status --short
+git rev-parse HEAD
+```
+
+Do not mark the validation successful if the test only passes under `--platform linux/amd64`; native ARM64 execution is required.
diff --git a/libs/python/cua-cli/cua_cli/commands/local_image.py b/libs/python/cua-cli/cua_cli/commands/local_image.py
index 42997e459a..830a76fed0 100644
--- a/libs/python/cua-cli/cua_cli/commands/local_image.py
+++ b/libs/python/cua-cli/cua_cli/commands/local_image.py
@@ -771,6 +771,10 @@ def _shell_linux_docker(args: argparse.Namespace, info: dict, name: str) -> int:
print_error(f"No Docker image configured for '{name}'")
return 1
+ config = PLATFORMS["linux-docker"]
+ internal_vnc_port = config["internal_vnc_port"]
+ internal_api_port = config["internal_api_port"]
+
user_vnc = getattr(args, "vnc_port", None)
user_api = getattr(args, "api_port", None)
@@ -806,9 +810,9 @@ def _shell_linux_docker(args: argparse.Namespace, info: dict, name: str) -> int:
"-t",
"--rm",
"-p",
- f"{vnc_port}:6901",
+ f"{vnc_port}:{internal_vnc_port}",
"-p",
- f"{api_port}:8000",
+ f"{api_port}:{internal_api_port}",
"--name",
container_name,
docker_image,
diff --git a/libs/python/cua-cli/cua_cli/commands/platform.py b/libs/python/cua-cli/cua_cli/commands/platform.py
index 8f1f22af70..3b3f82b786 100644
--- a/libs/python/cua-cli/cua_cli/commands/platform.py
+++ b/libs/python/cua-cli/cua_cli/commands/platform.py
@@ -24,9 +24,9 @@ from cua_cli.utils.output import console, print_error, print_info
PLATFORMS: Dict[str, Dict[str, Any]] = {
"linux-docker": {
- "image": "trycua/cua-xfce:latest",
+ "image": "public.ecr.aws/k5j5w0x5/cua-ubuntu-24.04:docker-latest",
"description": "Linux GUI container (no KVM required)",
- "internal_vnc_port": 6901,
+ "internal_vnc_port": 6080,
"internal_api_port": 8000,
"requires_kvm": False,
"image_marker": None,
diff --git a/libs/python/cua-cli/tests/commands/test_local_image.py b/libs/python/cua-cli/tests/commands/test_local_image.py
new file mode 100644
index 0000000000..b23a192270
--- /dev/null
+++ b/libs/python/cua-cli/tests/commands/test_local_image.py
@@ -0,0 +1,38 @@
+from argparse import Namespace
+from types import SimpleNamespace
+
+from cua_cli.commands import local_image
+
+
+def test_linux_docker_shell_uses_platform_internal_ports(monkeypatch) -> None:
+ calls = []
+
+ def fake_run(command, **kwargs):
+ calls.append(command)
+ if command[:2] == ["docker", "ps"]:
+ return SimpleNamespace(stdout="", stderr="", returncode=0)
+ return SimpleNamespace(stdout="container-id\n", stderr="", returncode=0)
+
+ monkeypatch.setattr(local_image.subprocess, "run", fake_run)
+
+ result = local_image._shell_linux_docker(
+ Namespace(vnc_port=16901, api_port=18000, detach=True),
+ {"docker_image": "example.invalid/cua-linux:test"},
+ "linux-docker",
+ )
+
+ assert result == 0
+ assert calls[-1] == [
+ "docker",
+ "run",
+ "-d",
+ "-t",
+ "--rm",
+ "-p",
+ "16901:6080",
+ "-p",
+ "18000:8000",
+ "--name",
+ "cua-shell-linux-docker",
+ "example.invalid/cua-linux:test",
+ ]
diff --git a/libs/python/cua-sandbox/cua_sandbox/runtime/images.py b/libs/python/cua-sandbox/cua_sandbox/runtime/images.py
index bd5e787ff8..285b261626 100644
--- a/libs/python/cua-sandbox/cua_sandbox/runtime/images.py
+++ b/libs/python/cua-sandbox/cua_sandbox/runtime/images.py
@@ -2,7 +2,7 @@
# ── Docker image tags ────────────────────────────────────────────────────────
-UBUNTU_XFCE = "trycua/cua-xfce:latest"
+UBUNTU_XFCE = "public.ecr.aws/k5j5w0x5/cua-ubuntu-24.04:docker-latest"
QEMU_LINUX = "trycua/cua-qemu-linux:latest"
QEMU_WINDOWS = "trycua/cua-qemu-windows:latest"
QEMU_ANDROID = "trycua/cua-qemu-android:latest"
@@ -21,7 +21,7 @@ MACOS_VERSION_IMAGES: dict[str, str] = {
# ── Internal ports (inside the container) ────────────────────────────────────
XFCE_API_PORT = 8000
-XFCE_VNC_PORT = 6901
+XFCE_VNC_PORT = 6080
QEMU_API_PORT = 5000
QEMU_VNC_PORT = 8006
diff --git a/libs/python/cua-sandbox/scripts/live_local_linux_docker.py b/libs/python/cua-sandbox/scripts/live_local_linux_docker.py
new file mode 100755
index 0000000000..f614f4b31e
--- /dev/null
+++ b/libs/python/cua-sandbox/scripts/live_local_linux_docker.py
@@ -0,0 +1,193 @@
+#!/usr/bin/env -S uv run --script
+# /// script
+# requires-python = ">=3.11,<3.14"
+# dependencies = ["cua-sandbox"]
+#
+# [tool.uv.sources]
+# cua-sandbox = { path = "..", editable = true }
+#
+# [[tool.uv.index]]
+# name = "cua-wheels"
+# url = "https://wheels.cua.ai/simple"
+# ///
+"""Exercise the local Linux Docker sandbox on a real host."""
+
+from __future__ import annotations
+
+import argparse
+import asyncio
+import json
+import os
+import platform
+import subprocess
+import uuid
+from pathlib import Path
+from typing import Any
+
+from cua_sandbox import Image, Sandbox
+
+
+def run_command(*command: str) -> subprocess.CompletedProcess[str]:
+ return subprocess.run(command, capture_output=True, text=True, check=False)
+
+
+def require_docker() -> str:
+ result = run_command("docker", "version", "--format", "{{.Server.Version}}")
+ if result.returncode != 0:
+ raise RuntimeError(f"Docker is unavailable: {result.stderr.strip()}")
+ return result.stdout.strip()
+
+
+def expected_container_architecture(host_architecture: str) -> str:
+ normalized = host_architecture.lower()
+ if normalized in {"arm64", "aarch64"}:
+ return "aarch64"
+ if normalized in {"amd64", "x86_64"}:
+ return "x86_64"
+ raise RuntimeError(f"Unsupported host architecture: {host_architecture}")
+
+
+def write_summary(artifact_dir: Path, summary: dict[str, Any]) -> None:
+ artifact_dir.mkdir(parents=True, exist_ok=True)
+ (artifact_dir / "summary.json").write_text(
+ json.dumps(summary, indent=2, sort_keys=True) + "\n",
+ encoding="utf-8",
+ )
+
+
+def collect_container_diagnostics(name: str, artifact_dir: Path) -> None:
+ artifact_dir.mkdir(parents=True, exist_ok=True)
+ for label, command in {
+ "docker-inspect.json": ("docker", "inspect", name),
+ "docker.log": ("docker", "logs", name),
+ }.items():
+ result = run_command(*command)
+ output = result.stdout
+ if result.stderr:
+ output += f"\n--- stderr ---\n{result.stderr}"
+ (artifact_dir / label).write_text(output, encoding="utf-8")
+
+
+def parse_args() -> argparse.Namespace:
+ parser = argparse.ArgumentParser(
+ description="Run the cua-sandbox local Linux Docker live test.",
+ )
+ parser.add_argument(
+ "--image",
+ default=os.environ.get("CUA_TEST_LINUX_DOCKER_IMAGE"),
+ help="Candidate image reference. Omit to test the built-in Linux container image.",
+ )
+ parser.add_argument(
+ "--artifact-dir",
+ type=Path,
+ default=Path(os.environ.get("CUA_TEST_ARTIFACT_DIR", "/tmp/cua-linux-arm64-live")),
+ help="Directory for screenshot, summary, and failure diagnostics.",
+ )
+ parser.add_argument(
+ "--allow-non-arm64",
+ action="store_true",
+ help="Permit execution on amd64 for diagnostic use.",
+ )
+ return parser.parse_args()
+
+
+async def run_live_test(args: argparse.Namespace) -> None:
+ host_architecture = platform.machine().lower()
+ if not args.allow_non_arm64 and host_architecture not in {"arm64", "aarch64"}:
+ raise RuntimeError(
+ f"Apple Silicon is required, found {host_architecture}. "
+ "Pass --allow-non-arm64 only for diagnostic runs."
+ )
+
+ docker_version = require_docker()
+ expected_architecture = expected_container_architecture(host_architecture)
+ if args.image:
+ image = Image.from_registry(args.image, os_type="linux", kind="container")
+ image_description = args.image
+ else:
+ image = Image.linux(kind="container")
+ image_description = "built-in Linux container image"
+
+ name = f"cua-linux-live-{uuid.uuid4().hex[:8]}"
+ clipboard_marker = f"{name}-{uuid.uuid4().hex}"
+ summary: dict[str, Any] = {
+ "docker_server_version": docker_version,
+ "host_architecture": host_architecture,
+ "image": image_description,
+ "sandbox_name": name,
+ "success": False,
+ }
+
+ print(f"Host architecture: {host_architecture}")
+ print(f"Docker server: {docker_version}")
+ print(f"Image: {image_description}")
+ print(f"Artifacts: {args.artifact_dir}")
+
+ try:
+ async with Sandbox.ephemeral(
+ image,
+ local=True,
+ name=name,
+ telemetry_enabled=False,
+ ) as sandbox:
+ try:
+ architecture = await sandbox.shell.run("uname -m")
+ if not architecture.success:
+ raise AssertionError(architecture.stderr)
+ container_architecture = architecture.stdout.strip()
+ summary["container_architecture"] = container_architecture
+ if container_architecture != expected_architecture:
+ raise AssertionError(
+ f"expected container architecture {expected_architecture}, "
+ f"got {container_architecture}"
+ )
+
+ screenshot = await sandbox.screenshot()
+ if not screenshot.startswith(b"\x89PNG\r\n\x1a\n"):
+ raise AssertionError("screenshot is not a PNG")
+ if len(screenshot) <= 10_000:
+ raise AssertionError(
+ f"screenshot is suspiciously small: {len(screenshot)} bytes"
+ )
+ args.artifact_dir.mkdir(parents=True, exist_ok=True)
+ (args.artifact_dir / "screenshot.png").write_bytes(screenshot)
+ summary["screenshot_bytes"] = len(screenshot)
+
+ width, height = await sandbox.get_dimensions()
+ if width <= 0 or height <= 0:
+ raise AssertionError(f"invalid screen dimensions: {width}x{height}")
+ summary["screen"] = {"width": width, "height": height}
+
+ await sandbox.clipboard.set(clipboard_marker)
+ clipboard_value = await sandbox.clipboard.get()
+ if clipboard_value != clipboard_marker:
+ raise AssertionError(
+ f"clipboard mismatch: expected {clipboard_marker!r}, got {clipboard_value!r}"
+ )
+ summary["clipboard_round_trip"] = True
+ except BaseException:
+ collect_container_diagnostics(name, args.artifact_dir)
+ raise
+ except BaseException as error:
+ summary["error"] = {"message": str(error), "type": type(error).__name__}
+ write_summary(args.artifact_dir, summary)
+ raise
+
+ inspect = run_command("docker", "inspect", "--type", "container", name)
+ if inspect.returncode == 0:
+ summary["cleanup_error"] = f"ephemeral container {name!r} was not removed"
+ write_summary(args.artifact_dir, summary)
+ raise AssertionError(summary["cleanup_error"])
+
+ summary["cleanup_verified"] = True
+ summary["success"] = True
+ write_summary(args.artifact_dir, summary)
+ print("PASS: local Linux Docker sandbox is healthy")
+
+
+def main() -> None:
+ asyncio.run(run_live_test(parse_args()))
+
+
+if __name__ == "__main__":
+ main()
diff --git a/libs/python/cua-sandbox/tests/live/test_local_linux_docker.py b/libs/python/cua-sandbox/tests/live/test_local_linux_docker.py
new file mode 100644
index 0000000000..af4c4fa919
--- /dev/null
+++ b/libs/python/cua-sandbox/tests/live/test_local_linux_docker.py
@@ -0,0 +1,30 @@
+"""Opt-in pytest wrapper for the local Linux Docker live script."""
+
+from __future__ import annotations
+
+import os
+import subprocess
+from pathlib import Path
+
+import pytest
+
+SCRIPT = Path(__file__).parents[2] / "scripts" / "live_local_linux_docker.py"
+ENABLED = os.environ.get("CUA_TEST_LOCAL_LINUX_DOCKER", "").lower() in {
+ "1",
+ "true",
+ "yes",
+}
+
+pytestmark = pytest.mark.skipif(
+ not ENABLED,
+ reason="CUA_TEST_LOCAL_LINUX_DOCKER is not enabled",
+)
+
+
+def test_local_linux_docker_live_script() -> None:
+ result = subprocess.run(
+ [str(SCRIPT)],
+ text=True,
+ check=False,
+ )
+ assert result.returncode == 0
diff --git a/libs/python/cua-sandbox/tests/test_runtime_images.py b/libs/python/cua-sandbox/tests/test_runtime_images.py
new file mode 100644
index 0000000000..4eb08821e5
--- /dev/null
+++ b/libs/python/cua-sandbox/tests/test_runtime_images.py
@@ -0,0 +1,8 @@
+from cua_sandbox.runtime.images import internal_ports, resolve_image
+
+
+def test_linux_docker_uses_unified_multiarch_rootfs() -> None:
+ image = resolve_image("linux")
+
+ assert image == "public.ecr.aws/k5j5w0x5/cua-ubuntu-24.04:docker-latest"
+ assert internal_ports(image) == (8000, 6080)