Try these tips to resolve the issue:
Check your device's power
Make sure your device's batteries aren't low. If you're using Magic Trackpad 2 or Magic Mouse 2, make sure its rechargeable battery is fully charged.
Avoid accidental multiple touches on the surface
Be sure only one part of your finger is touching the touch surface and that you're not resting your wrist on or very close to the surface. The touch surface might interpret this as your finger touching it and move the pointer in that direction.
Keep touch surface dry and clean
Moisture collecting on the touch surface can also cause this issue. Wiping off the surface of the trackpad or mouse with a cloth or tissue usually fixes this.
If the issue goes away when you put a piece of paper between your finger and the touch surface, consider purchasing a Teflon applique to fit over the surface to prevent moisture from having direct contact with the touch surface. Before you install the Teflon applique, make sure the touch surface is clean and dry.
Note that oil or lotion can also cause the same issue. You can clean your device's touch surface with a lint-free cloth lightly moistened with water.
Jewelry might also cause interference when you use a device with a touch surface. Try removing rings or bracelets and see whether the jumpy or erratic behavior disappears.
Check the power adapter you're using with your Mac
This behavior might happen if you use a power adapter made by a third-party company.
If you're using one of these power adapters, unplug it and try running your Mac from battery power to see whether the pointer behaves correctly. If the device behaves normally while running from the battery, there might be an issue with your power adapter.
Avoid wireless interference
Bluetooth devices can act erratically when there's wireless interference. See Wi-Fi and Bluetooth: Potential sources of wireless interference for more information.
Start your Mac in Safe Mode
If none of the above resolves the issue, you can start in Safe Mode to rule out third-party software as a cause.