All serverless function time out after 10 seconds by default (an increase to 26 seconds is possible.)
Serverless functions aren’t meant to run as servers.
Here is a very basic example of a serverless function from Netlify Functions Playground
exports.handler = function (event, context, callback) {
callback(null, {
statusCode: 200,
body: "Hello, World",
});
};