Yes that’s fine but it has to be very safe, no predators able to get in etc.
I keep my two boys outside in a 5 foot by 2 foot hutch which is in an 8ft by 6ft shed. They have constant access during daylight hours out to play within my shed itself (and then their lawn run for when it’s dry and warm)
There are two issues which are faced when keeping piggies in sheds/outbuildings and that is heat and cold. From April onwards, heat builds in My shed very quickly so I have to ensure the door and window is open and air is circulating from fairly early in the morning and from mid summer, they have to be removed from the shed and put into their lawn run by 9am otherwise it gets too hot in there. They can’t go back in until around 9pm when it has cooled enough.
Winter is also an issue and keeping them warm enough. If you can’t heat the outbuilding, then you will need to plan for what to do over winter. I use several blankets, a thermal hutch cover over their hutch and then throw a further duvet over the top of all of it. Snugglesafe heat pads are used once it gets below 12 degrees to ensure the stay warm enough. I always have a spare cage though to be able to bring them indoors if I can’t maintain temperatures for them outside.