I'm not a seasoned coder, but it would see to be possible. if you can get the code into the c2runtime.js file and not break the existing logic.
i think squeezing something like an api call in would be doable... what i think would get hairy is trying to manipulate game logic and actions with code.
Also keep in mind that you might also want to look into making a plugin. plugins are basically just snippets of javascript. plug in your custom code and access it from C2.