No, this is not a supported workflow, the reason is that the pythonscript workitems cook in parallel and off the main thread, and this will cause mayhem and probably crash if the functions they use are not thread safe.
Using the houdini command chain would probably be a safer way to go.
Otherwise, you could force your code run on the main thread like so:
import hou
import hdefereval
# BAD
# hou.node('/obj/box1').createNode('heightfield_file')
def doit():
n = hou.node('/obj/box1').createNode('heightfield_file')
n.parm('filename').set('$HIP/test')
hdefereval.executeInMainThreadWithResult(doit)