npx tsx device.ts, and passes everything the model says to the operating system as arguments, never inside a shell command. You need Node 18 or later, an agent created with lua init, and on macOS the Screen Recording permission for your terminal.
Verified against lua-cli 3.45.0.
What you’ll build
- A device named
my-laptopwith six commands the model can call. - Screenshots uploaded to the CDN so the agent can share an image URL.
- An allow-list for the applications the agent may open.
- A notification, volume, and lock-screen command driven by sanitized arguments.
1
Create the credential
From the agent project, issue a device credential for device name
my-laptop with the operations commands and assets.upload, written to the folder the device will run from. Then load it there and install the client.2
Write the device
Model output reaches the OS only as
execFileSync arguments or environment variables, and open_app checks an allow-list first.- macOS
- Windows
device.ts
3
Run the device
Start the script and leave it running. It prints
my-laptop connected; on macOS the first screenshot prompts for the Screen Recording permission.4
Ask the agent
From the agent project, try each command. The model calls
device__my_laptop__take_screenshot and replies with the image URL; open_app refuses anything outside the allow-list and the model reports the error.5
Verify
Check the device state from the agent project.It prints
🟢 Device 'my-laptop' is online; stop the script and it prints offline and the tools disappear from the agent.What you learned
- A device describes its commands at connect time; no agent code changed. See Expose device commands as tools.
inputSchemawithenumplus a check in the handler keeps model output out of shell strings.device.cdn.uploadneeds theassets.uploadoperation. See Upload files from a device.- Tools exist only while the device is online. See How devices work.
Next steps
Handle device triggers
Let the laptop wake the agent, for example on low battery.
Node device client
Every option and event of the client.

