I was testing this in another aspect and threw together a rough Postman collection of the run-script command with a fw sam command example, also included the other commands needed for a build out: login/login (w/domain), run-script, logout.
With the Postman collection, you can use Postman to test the approach against your own environment and the use the code option in postman to build web code for your implementation approach.
This collection also abstracts some things in to environment variables for login/login(w/domain) such that no credential information is in the collection itself.