How to bake dynamic paint surfaces headlessly?
import bpy

obj=bpy.data.objects['Cube']
modifier=obj.modifiers['Dynamic Paint']
canvas_surface=modifier.canvas_settings.canvas_surfaces['Surface']
point_cache=canvas_surface.point_cache

context={}
context['blend_data']=bpy.data
context['scene']=bpy.data.scenes['Scene']
context['active_object']=obj
context['point_cache']=point_cache

bpy.ops.ptcache.bake(context,bake=True)


Objects can be both a brush and a canvas. The baking is done by the surfaces of the canvas. So an additional iteration is necessary.

#...
for modifier in obj.modifiers:
    if modifier.type=='DYNAMIC_PAINT':
        #additional iteration
        for canvas_surface in modifier.canvas_settings.canvas_surfaces:
             context['active_object']=obj
             context['point_cache']=canvas_surface.point_cache
             bpy.ops.ptcache.bake(context,bake=True)