No, you generally cannot use a UFW firewall inside an OpenVZ container. The reason for this is that OpenVZ uses a shared kernel architecture and doesn’t give containers direct access to some networking modules.
UFW, or Uncomplicated Firewall, is a Linux program for managing a netfilter firewall. Since OpenVZ containers share a kernel with their host, it’s up to the host’s kernel to manage IPTABLES/firewall rules, not individual containers.
If you need to enact firewall rules in an OpenVZ environment, they should be set up on the host machine to apply to all containers. Alternatively, you could consider switching from OpenVZ to another container/virtualization technology that allows container-specific firewall rules, such as Docker or KVM.
Check with your host/provider for any custom policies they may have established regarding container firewalls.