Adding images to a node
If by 'programmatically' you mean using PHP, then there seem to be two good options.


Create a template file, include the fancybox library if not already loaded, load the file path/names from your image directory into an array, tweak the array as needed, and call fancybox with the paths in your array.
Create a custom module that does essentially the same thing, but here you can also add an admin view to manage the images, set custom permissions, etc.