If your AirPods are rattling, it's likely because there is something caught in the speaker mesh. To fix this, you'll need to take your AirPods apart and clean the speaker mesh with a toothpick or other small object.
First, start by removing the rubber tips from your AirPods. Next, use a paperclip or another small object to gently pry open the seam between the body of the AirPod and the earbud cover. Be careful not to damage the delicate components inside.
Once you've opened up your AirPod, you'll see the speaker mesh covering the earbud driver. Use a toothpick or other sharp object to clear any debris that's caught in the mesh. Be sure to remove any debris from both sides of the mesh so that sound can travel through freely.
Finally, reassemble your AirPod and replace the rubber tip. Your AirPod should now be rattle-free!