tacker69 You could try writing a tasker profile; I'm 99% sure it will work.
Here is the example for the "panic button" wipe: https://www.reddit.com/r/tasker/comments/1bantau/comment/ku43ycl/
It requires a plugin to be installed and granted elevated permissions.
For wiping triggered via SMS (which Tasker will let you handle as well) you could try "FindMyDevice" app, it supports that command.
So, to answer your question: yes, you can write such code and install it on your phone (make sure your APK requests all the permissions it needs), or you can use the existing tools.