Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
073596e
feat(computer): the app runtime on Windows: a session of its own and …
earakely-scale Nov 8, 2026
92ca357
feat(computer): declare a Windows app with @windows; reap a launch by…
earakely-scale Nov 8, 2026
4063ab5
test(computer): @windows takes every Windows field and declares its i…
earakely-scale Nov 8, 2026
9519510
fix(computer): pause a Windows app's processes until none is new, and…
earakely-scale Nov 8, 2026
cc397e3
feat(computer): compose apps onto a Windows computer
earakely-scale Nov 8, 2026
8b57ba8
test(computer): refuse a session install step on Windows alone or com…
earakely-scale Nov 8, 2026
d9133e4
refactor(computer): name the driver's Windows prefix apart from each …
earakely-scale Nov 8, 2026
40bd73f
fix(computer): run a Windows app's job helper on the base interpreter…
earakely-scale Nov 8, 2026
cd63b2e
Merge branch 'edgararakelyan/windows-app-runtime' into edgararakelyan…
earakely-scale Nov 8, 2026
d29bd03
feat(computer): leave a Windows computer's agentenv folder the admins…
earakely-scale Nov 8, 2026
89f45b0
fix(computer): a Windows app's stop waits until the job it ended hold…
earakely-scale Nov 8, 2026
a5863e5
Merge branch 'edgararakelyan/windows-app-runtime' into edgararakelyan…
earakely-scale Nov 8, 2026
e73ce0f
fix(computer): a Windows app is alive while its job holds a process, …
earakely-scale Nov 8, 2026
72c1f5d
Merge branch 'edgararakelyan/windows-app-runtime' into edgararakelyan…
earakely-scale Nov 8, 2026
268592a
test(computer): keep the Windows notes test in the Windows bundle
earakely-scale Nov 8, 2026
564806a
fix(computer): a Windows compose tries a layer's download again after…
earakely-scale Nov 8, 2026
514070e
fix(computer): a Windows compose tries a download as long as the base…
earakely-scale Nov 8, 2026
11bb9f6
test(computer): the protocol's Windows session launches, pauses and s…
earakely-scale Nov 8, 2026
de98352
refactor(computer): reach an app's server by its OS's transport, from…
earakely-scale Nov 8, 2026
bc4b160
Merge branch 'edgararakelyan/windows-app-runtime' into edgararakelyan…
earakely-scale Nov 8, 2026
71695ab
fix(computer): a Windows app's stop waits for each process it ended t…
earakely-scale Nov 8, 2026
877dcb3
Merge branch 'edgararakelyan/windows-app-runtime' into edgararakelyan…
earakely-scale Nov 8, 2026
060e34f
test(computer): the Windows session check reads sizes through a handl…
earakely-scale Nov 8, 2026
0b9829f
Merge remote-tracking branch 'origin/main' into edgararakelyan/window…
earakely-scale Nov 8, 2026
8715a2a
fix(computer): a Windows compose fails a download at once on a client…
earakely-scale Nov 8, 2026
368de02
refactor(computer): a Windows app's folder from one place, its access…
earakely-scale Nov 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/agent_env/computers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ link serves then. Name it as `windows-11`, or by its id, `@local/agentenv-framew

A Windows computer env is composed on the same machine (`env/envs/computer/utils/windows_disk.py`): the base booted on
an overlay kept in a folder of its own, each layer installed over ssh as `agentadmin` by a PowerShell script composing
writes, as its `[install.windows]` says (its files under `C:\agentenv\drivers\<name>`, its downloads checked by
sha256, its venv on the pinned Python, its PowerShell run scripts, elevated, and its services), then shut down and
writes, as its `[install.windows]` says (its files under `C:\agentenv\drivers\<name>`, or an app's under
`C:\agentenv\apps\<name>`, its downloads checked by sha256, its venv on the pinned Python, its PowerShell run scripts,
elevated, an app's install steps, elevated too, and its services), then shut down and
packed onto the base's image, so every computer composed on a base shares one copy of it, and pushed to the env's image
store under its key, pinned, as a Linux disk is; a compose of the same inputs on any machine reuses it, and a deploy
pulls it. Gate 3 probes it at full. At the session user's sign-in,
Expand All @@ -177,7 +178,12 @@ media alone, and starts each layer's services in that session, again whenever on
with 4 vCPUs and 8 GB, on local Docker with KVM and on `modal_vm`; it has computer-exec and data/add, through the
protocol's Windows defaults, so the probe runs its fixture there as on Linux, with Python one-liners for the commands it
would give a shell. On `modal_vm` it runs in your own Modal workspace, under the evaluation's terms or a licence of your
own; whether they allow it there is yours to check. A Windows computer composes its driver alone for now, no app.
own; whether they allow it there is yours to check. Composing leaves `C:\agentenv` the admins', as `/opt/agentenv` is
root's on Linux: every user reads and runs what's there, and the session user writes only the services' logs and each
app's `.agentenv` folder. An app's own server runs in the session as its services do, on a loopback port it writes
with a token to that folder, which only the session user, SYSTEM and Administrators reach; it launches the app in a
Job object, which ends whatever the app started. Composing signs in as `agentadmin`, so
an app's install step for the session user can't run on Windows, and gate 1 refuses an app that declares one there.

This bundle has no tasks of its own: other bundles pull its computers by alias, and `agent-env run computers` has
nothing to run.
59 changes: 39 additions & 20 deletions src/agent_env/env/envs/computer/utils/composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import urllib.parse
from concurrent.futures import Future, ThreadPoolExecutor, as_completed
from dataclasses import dataclass, replace
from pathlib import Path, PurePosixPath
from pathlib import Path, PurePosixPath, PureWindowsPath
from collections.abc import Callable, Iterator
from typing import TYPE_CHECKING, Any, Literal

Expand Down Expand Up @@ -313,7 +313,7 @@ def _composed_vm_bundle(env: ComputerEnv, base: ComputerArtifact, driver: Comput
parts = [_part(layer, _services(f"driver-{gate.folder_name(driver.id, 'driver')}", layer.install),
{"MCP_PORT": driver.port}, protocol, False)]
parts += [_part(staged, dict(zip(gate.programs(app, base.os.type), [
f"venv/bin/python -m agentenv_protocol.computer.serve_app {staged.served}",
f"venv/bin/python -m agentenv_protocol.computer.serve_app {shlex.quote(staged.served)}",
*(service.command for service in staged.install.services)])), {"ENVIRONMENT_NAME": app.environment_name},
protocol, True) for app, staged in apps]
if (lock := _vm_bundle_lock(env, base, link, parts, context, arch, progress)) is not None:
Expand Down Expand Up @@ -357,29 +357,34 @@ def _composed_windows_disk(env: ComputerEnv, base: ComputerArtifact, driver: Com
provider: SandboxProvider, progress: _Progress) -> dict:
"""The Windows disk of ``arch``: one of its key the env's image store holds, reused; else composed with this
machine's Docker and KVM (``windows_disk``), on its base, this machine's, the store's or installed from Microsoft's
media, the driver installed over ssh as a layer on it, packed and pushed to the store under its key, as Linux disks
are. Then probed at full (gate 3). All of it holds a lock of its key, which keeps two composes of one key on this
machine from breaking each other: the other waits, then reuses it."""
media, the driver and each app installed over ssh as a layer on it, packed and pushed to the store under its key,
as Linux disks are. Then probed at full (gate 3). All of it holds a lock of its key, which keeps two composes of one
key on this machine from breaking each other: the other waits, then reuses it."""
pair = f"disk/{arch}"
with (_attempting(env, "disk", arch) as attempt,
tempfile.TemporaryDirectory(prefix="agentenv-compose-") as work):
if not boot.native_links(provider, arch, "disk", env.stored_id, "windows"):
raise builder.Unbuildable(f"no link of {' or '.join(type(link).__name__ for link in provider.links)} boots "
f"windows/{arch} disks, so it can't be composed here: compose it on a Linux machine "
"with KVM, with the local sandbox provider")
if env.composed_apps():
raise builder.Unbuildable("a Windows computer composes its driver alone for now, and no app")
build = Path(work) / "build"
context = build / "context"
context.mkdir(parents=True)
protocol = _stage_protocol(context)
layer = _stage_driver(context, driver, base, {})
prefix = windows_disk.DRIVERS / gate.folder_name(driver.id, "driver")
services = _services(f"driver-{gate.folder_name(driver.id, 'driver')}", layer.install)
part = windows_disk.Part(layer.folder, prefix, layer.install,
{name: windows_disk.argv(command, prefix) for name, command in services.items()},
{"MCP_PORT": driver.port},
(f"{windows_disk.BUILD}\\context\\protocol",) if protocol else ())
layer, name = _stage_driver(context, driver, base, {}), gate.folder_name(driver.id, "driver")
driver_prefix = windows_disk.DRIVERS / name
parts = [_windows_part(layer, driver_prefix, {
program: windows_disk.argv(command, driver_prefix)
for program, command in _services(f"driver-{name}", layer.install).items()}, {"MCP_PORT": driver.port},
protocol)]
for app in env.composed_apps():
staged = _stage_app(context, app, base, {})
prefix = PureWindowsPath(staged.prefix)
server = [str(prefix / "venv" / "Scripts" / "python.exe"), "-m", "agentenv_protocol.computer.serve_app",
staged.served]
commands = [server, *(windows_disk.argv(service.command, prefix) for service in staged.install.services)]
parts.append(_windows_part(staged, prefix, dict(zip(gate.programs(app, base.os.type), commands)),
{"ENVIRONMENT_NAME": app.environment_name}, protocol))
values = env.computer_values()
settings = {name: values.get(name, setting.default) for name, setting in base.config.items()
if setting.phase == "build"}
Expand All @@ -393,7 +398,8 @@ def say(line: str) -> None:
made = windows_disk.base(_key(recipe=_digest(windows_disk.RECIPE), disk_gb=disk_gb, user=user,
form="windows-base", format=FORMAT),
lambda: windows_disk.media(say), disk_gb, user, say, registry)
script = windows_disk.write(build, [part], settings, {"base": made.image, "layers": [part.folder]})
script = windows_disk.write(build, parts, user=user, build_settings=settings,
image={"base": made.image, "layers": [part.folder for part in parts]})
expires = made.expires.isoformat(timespec="seconds")
key = attempt.key = _key(base=made.image, base_expires=expires, provision=script, context=_digest(context),
build_settings=settings, form="disk", arch=arch, format=FORMAT)
Expand Down Expand Up @@ -494,6 +500,18 @@ def _part(layer: _Layer, programs: dict[str, str], environment: dict[str, Any],
environment, _venv(layer), spec if _venv(layer) else None, layer.served, layer.steps)


def _windows_part(layer: _Layer, prefix: PureWindowsPath, services: dict[str, list[str]],
environment: dict[str, Any], protocol: bool) -> windows_disk.Part:
"""``layer`` as a Windows disk installs it under ``prefix``: its ``services``' argv by name, with ``environment``,
and a venv's protocol as on Linux: this checkout's source, else an app's pinned to this release, which a driver's
requirements name themselves."""
extra = "[app]" if layer.app else ""
spec = (f"{windows_disk.BUILD}\\context\\protocol{extra}" if protocol else
f"{_PROTOCOL}{extra}=={importlib.metadata.version(_PROTOCOL)}" if layer.app else None)
return windows_disk.Part(layer.folder, prefix, layer.install, services, environment, (spec,) if spec else (),
layer.served, tuple(step for step, _ in layer.steps))


def _probed(env: ComputerEnv, driver: ComputerDriverEnv, form: str, arch: str, result: dict,
sandbox_provider: SandboxProvider, progress: _Progress) -> dict:
"""Gate 3: the build of ``result`` booted on the first link of ``sandbox_provider`` that runs ``arch``'s ``form``
Expand Down Expand Up @@ -745,8 +763,9 @@ def _base(base: ComputerArtifact, arch: str) -> tuple[str, str]:
@dataclass(frozen=True)
class _Layer:
"""A driver's or an app's part of a build: its folder in the build context, its prefix in the image, what it
installs, the file of its supervisord programs, and the id of its env. An app's venv also has the protocol's ``app`` extra, for the
app's own server, which listens in a folder of the app's the session user owns."""
installs, the file of its supervisord programs, and the id of its env. An app's venv also has the protocol's ``app``
extra, for the app's own server, which listens in a folder of the app's the session user owns; ``served`` is the
``<file>:<Class>`` it serves, and ``steps`` its install steps, by name and scope."""

folder: str
prefix: str
Expand Down Expand Up @@ -778,13 +797,13 @@ def _stage_app(context: Path, app: ComputerAppEnv, base: ComputerArtifact,
name."""
install, name = app.install[base.os.type], gate.app_folder(app)
file, _, cls = app.module.partition(":")
served = shlex.quote(f"{PurePosixPath(file).relative_to(install.files)}:{cls}")
served = f"{PurePosixPath(file).relative_to(install.files)}:{cls}"
layer = _Layer(f"apps/{name}", str(apps_folder(base.os.type) / name), install, f"agentenv-app-{name}.conf", app.id,
app=True, served=served,
steps=tuple((step.name, step.scope) for step in app.declaration.install_steps
if step.os is None or base.os.type in step.os))
programs = dict(zip(gate.programs(app, base.os.type), [
f"venv/bin/python -m agentenv_protocol.computer.serve_app {served}",
f"venv/bin/python -m agentenv_protocol.computer.serve_app {shlex.quote(served)}",
*(service.command for service in install.services)]))
_stage(context, layer, f"app {app.id}", app.files, programs, {"ENVIRONMENT_NAME": app.environment_name},
from_store)
Expand Down Expand Up @@ -915,7 +934,7 @@ def _runs(layer: _Layer) -> list[tuple[str, str]]:
a build that write outside the layer's folder."""
return [*((run.scope, f"cd {layer.prefix} && {shlex.quote('./' + run.script)}") for run in layer.install.run or []),
*((scope, f"cd {layer.prefix} && venv/bin/python -m agentenv_protocol.computer.run_install_step "
f"{layer.served} {step}") for step, scope in layer.steps)]
f"{shlex.quote(layer.served)} {step}") for step, scope in layer.steps)]


def _as(scope: str, user: str, run: str) -> list[str]:
Expand Down
8 changes: 7 additions & 1 deletion src/agent_env/env/envs/computer/utils/gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ def arches(base: ComputerArtifact, driver: ComputerDriverEnv, apps: Sequence[Com

def check_app(base: ComputerArtifact, driver: ComputerDriverEnv, app: ComputerAppEnv, at: str = "app") -> list[str]:
"""Every way ``app`` doesn't fit a composition of ``base`` and ``driver``, each named from ``at``: a platform it
doesn't support, no architecture in common, no install for the base's OS, or a port the driver listens on too."""
doesn't support, no architecture in common, no install for the base's OS, a port the driver listens on too, or on
Windows an install step for the session user, as a Windows computer is composed over ssh as its admin."""
os = base.os
if not _matching(base, app.declaration.supports):
named = ", ".join(_shown(platform) for entry in app.declaration.supports for platform in supported(entry))
Expand All @@ -78,6 +79,11 @@ def check_app(base: ComputerArtifact, driver: ComputerDriverEnv, app: ComputerAp
problems.append(f"{at}: {app.id} declares no install for {os.type}")
elif taken := sorted(set(_ports(app, os.type)) & set(_driver_ports(driver, os.type))):
problems.append(f"{at}: {app.id} listens on {', '.join(map(str, taken))}, as {driver.id} does")
if os.type == "windows" and (session := [step.name for step in app.declaration.install_steps
if step.scope == "session" and (step.os is None or os.type in step.os)]):
problems.append(f"{at}: {app.id}'s install steps {', '.join(session)} run as the session user, which a Windows "
"computer can't as it's composed, over ssh as its admin; give them scope \"system\" for "
"Windows")
return problems


Expand Down
3 changes: 2 additions & 1 deletion src/agent_env/env/envs/computer/utils/macos_vm_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ def _installed(part: Part) -> list[str]:
if part.served is not None:
lines.append(f"mkdir -p {shlex.quote(f'{prefix}/{SOCKET.parent}')}")
commands = [*((run.scope, shlex.quote(f"./{run.script}")) for run in install.run or []),
*((scope, f"venv/bin/python -m agentenv_protocol.computer.run_install_step {part.served} {step}")
*((scope, f"venv/bin/python -m agentenv_protocol.computer.run_install_step {shlex.quote(part.served)} "
f"{step}")
for step, scope in part.steps)]
for scope, command in commands:
run = f"cd {quoted} && {command}"
Expand Down
Loading
Loading