Problem with bpy.ops.sculpt.mask_expand
Not in sculpt mode.
Result in python console of changing absolute mode of object to 'SCULPT' followed by toggling mode
&gt;&gt;&gt; bpy.ops.object.mode_set(mode='SCULPT')
{'FINISHED'}

&gt;&gt;&gt; bpy.ops.sculpt.sculptmode_toggle()
{'FINISHED'}

&gt;&gt;&gt; C.mode
'OBJECT'

hence out of context, since bpy.ops.sculpt.* operators require sculpt mode for context.
Remove toggle to remain in sculpt mode or  move to  the last line to toggle.
Tip
Making a poll method for your operator returning false for selected objects that cannot be sculpted will disable button in UI and remove it from context operator search.