I'm not a mechancial engineering but it would seem you would have to simulate the explosive gas expansion rate and its acceleration of the bullet, in reverse.
Perhaps a dampened spring with a solenoid pulsed rod. You have to de-accelerate the rod over time to make is closer to realistic feel. You're alway going to have some forward deceleration forward force after the initial recoil unless you actually launch a projectile. All you can do is soften it by stretching it out in time.
Now for electrical, a rare earth magnet pellet, coil around breech, charge a supercap and discharge it to coil to launch magnet pellet. Then decelerate it with spring and return magnet to original breech position. You will have to vent barrel or compressed air will dampen launch. Perhaps just rails for pellet track to allow air to flow around magnet pellet.
Then hope the end cap does not come off.