The simplest way to go about this would be to use math.sin or math.cos, as you’ve suggested, on the camera’s y rotation. You would need to initialize a number that constantly increases in increments from 0-360 degrees or 2π radians in a loop, and resets to 0 once a full revolution has been made (360 if you use degrees, 2π if you use radians). With this number, you can plug it in math.sin or math.cos to get a value that ranges from [-1, 1] (use sin if you want each rotation to finish at y=0 or cos to finish the rotation at y=1). This value can constantly be added to the y rotation of the camera inside a RenderStep to create the bob effect.
My personal choice, though the camera sway comes from the animations instead of code, so it’s not as clean as doing it algorithmically. It’s drag and drop though, and adds lots of other immersive features for first person (I assume you’re doing a horror game from the reference).
The ones below are really simple to add, but this module lets you make immersive animations without view models and the client-server replication code you’d need for that. If you’re not looking for that, you can use the ones below (though I’d still recommend the foot step sounds from the one above, even if you disable the other features).
These might be good too:
(This one has everything to do with what you’re interested in)
One way of making this is you use a wave function like sine or cosine for the swaying, and use a spring module (Quenty has a great one in nevermore engine that I use) to smooth out the camera animations (a spring basically adds physics in a way, so you set a goal and it “springs” to the goal you set). You can also use the spring to add a “weighty” feel when you rotate the camera that feels immersive.
I would use the things above though, as they’re easier and probably mostly implemented at a fairly skilled level (realism especially).