Is there a word for "back and forth"?

Solution 1:

Oscillates fits the machine example, but not (very well) the hand example.

Possibilities for the hand movement are wildly or repeatedly. The latter could also fit the machine case.

Solution 2:

I think a common term for this type of movement in machinery is reciprocating.

alternating back-and-forth movement

Google images for reciprocating.

Solution 3:

Seesaw.

Noun:

an up-and-down or a back-and-forth movement or procedure.

Adjective:

moving up and down, back and forth, or alternately ahead and behind: It was a seesaw game with the lead changing hands many times.

Solution 4:

You can use Sway , it might only apply for your first sentence. As Google's definition:

move or cause to move slowly or rhythmically backward and forward or from side to side.