Files
zeekayandHanzo Dev a386271c80 isolation is a value the org sets, and an empty one is not runc
Every sandbox was created privileged under the daemon's default runtime, and
the setting that would have changed it defaulted to an empty string that
silently meant runc. For a service whose whole premise is running code
somebody else wrote, that is not a boundary.

An org sets its isolation and the create request carries it, so a sandbox
records what it was made with: changing the policy moves new sandboxes and
leaves running ones alone. gvisor is the default. firecracker is delivered
through kata's shim, which is why it is one name rather than two. runc is
refused unless the runner names that org, and an empty list names nobody.

Absent means the default, unknown is a refusal, and a runtime the daemon does
not have is a refusal. Nothing substitutes quietly.

The runner took an organization in a field called UserId with a note beside
it saying so. Deciding who may have runc through a field named after
something else is not reviewable.

Privileged is replaced by dropping everything and granting the eight the
daemon uses. Nothing the sandbox does broke; what stopped working is mount,
mknod, raw sockets, chroot, writing to proc, and seeing the host's disks.
AUDIT_WRITE is among them because without it sudo works and complains every
time.

The creation histogram's lowest bucket was a tenth of a second, so the metric
could not observe the claim the product makes about its own speed. It can
now, and it carries the isolation, so comparing them is a query.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-11 13:47:31 -07:00

158 lines
3.6 KiB
Go

// Copyright 2025 Hanzo Industries Inc.
// SPDX-License-Identifier: AGPL-3.0
package computeruse
import (
"os"
"time"
"github.com/hanzoai/runtime/apps/daemon/pkg/toolbox/computeruse"
"github.com/go-vgo/robotgo"
log "github.com/sirupsen/logrus"
)
func (u *ComputerUse) GetMousePosition() (*computeruse.MousePositionResponse, error) {
// Debug: Check DISPLAY environment variable
display := os.Getenv("DISPLAY")
log.Infof("GetMousePosition: DISPLAY=%s", display)
x, y := robotgo.Location()
return &computeruse.MousePositionResponse{
Position: computeruse.Position{
X: x,
Y: y,
},
}, nil
}
func (u *ComputerUse) MoveMouse(req *computeruse.MoveMouseRequest) (*computeruse.MousePositionResponse, error) {
robotgo.Move(req.X, req.Y)
// Small delay to ensure movement completes
time.Sleep(50 * time.Millisecond)
// Get the mouse position after move
actualX, actualY := robotgo.Location()
return &computeruse.MousePositionResponse{
Position: computeruse.Position{
X: actualX,
Y: actualY,
},
}, nil
}
func (u *ComputerUse) Click(req *computeruse.ClickRequest) (*computeruse.MouseClickResponse, error) {
// Default to left button
if req.Button == "" {
req.Button = "left"
}
// Move mouse to position first
robotgo.Move(req.X, req.Y)
time.Sleep(100 * time.Millisecond) // Wait for mouse to move
// Perform the click
if req.Double {
robotgo.Click(req.Button, true)
} else {
robotgo.Click(req.Button, false)
}
// Get position after click
actualX, actualY := robotgo.Location()
return &computeruse.MouseClickResponse{
Position: computeruse.Position{
X: actualX,
Y: actualY,
},
}, nil
}
// Helper function to move mouse smoothly in steps
func moveMouseSmoothly(startX, startY, endX, endY, steps int) {
dx := float64(endX-startX) / float64(steps)
dy := float64(endY-startY) / float64(steps)
for i := 1; i <= steps; i++ {
x := int(float64(startX) + dx*float64(i))
y := int(float64(startY) + dy*float64(i))
robotgo.Move(x, y)
time.Sleep(2 * time.Millisecond)
}
}
func (u *ComputerUse) Drag(req *computeruse.DragRequest) (*computeruse.MouseDragResponse, error) {
// Default to left button
if req.Button == "" {
req.Button = "left"
}
// Move to start position
robotgo.Move(req.StartX, req.StartY)
time.Sleep(100 * time.Millisecond)
// Click to focus window before drag
robotgo.Click(req.Button, false)
time.Sleep(100 * time.Millisecond)
// Ensure mouse button is up before starting
err := robotgo.MouseUp(req.Button)
if err != nil {
return nil, err
}
time.Sleep(50 * time.Millisecond)
// Press and hold mouse button
err = robotgo.MouseDown(req.Button)
if err != nil {
return nil, err
}
time.Sleep(300 * time.Millisecond) // Increased delay
// Move to end position while holding (smoothly)
moveMouseSmoothly(req.StartX, req.StartY, req.EndX, req.EndY, 20)
time.Sleep(100 * time.Millisecond)
// Release mouse button
err = robotgo.MouseUp(req.Button)
if err != nil {
return nil, err
}
time.Sleep(50 * time.Millisecond)
// Get final position
actualX, actualY := robotgo.Location()
return &computeruse.MouseDragResponse{
Position: computeruse.Position{
X: actualX,
Y: actualY,
},
}, nil
}
func (u *ComputerUse) Scroll(req *computeruse.ScrollRequest) (*computeruse.ScrollResponse, error) {
// Default amount if not specified
if req.Amount == 0 {
req.Amount = 3
}
// Move mouse to scroll position
robotgo.Move(req.X, req.Y)
time.Sleep(50 * time.Millisecond)
// Perform scroll
if req.Direction == "up" {
robotgo.ScrollSmooth(req.Amount, 0)
} else {
robotgo.ScrollSmooth(-req.Amount, 0)
}
return &computeruse.ScrollResponse{
Success: true,
}, nil
}