The script works for me. That is, unless you intend something else. If you select both glyphs with paths and with (unaligned) components, you are moving the components twice, and correcting them once.
The problem you have is that it does not anticipate the order in which the glyphs get processed. IOW, if B contains A as a component, it makes a difference if you run it with AB or BA selected.
Here is slightly cleaned-up version of the above:
thisFont = Glyphs.font
compoundList =[]
left = 10
right = 10
for g in thisFont.selectedLayers:
g.LSB = g.LSB + left
g.RSB = g.RSB + right
glyph = g.parent
reused = thisFont.glyphsContainingComponentWithName_masterID_(glyph.name, thisFont.selectedFontMaster.id)
compoundList.extend(reused)
for glyph in compoundList:
layer = glyph.layers[thisFont.selectedFontMaster.id]
comp = layer.components[0]
comp.position.x -= left
But please tell me what exactly should happen with A and B after running this script, like an example: A (paths) LSB=40, RSB=40; B (contains component of A), LSB=30, RSB=30.