Not possible to set a time limit on workers?

My worker script will run arbitrary user code (passed in via request body), and I’d like to only allow the user code to run for a maximum of 50ms CPU time, and 5 seconds total duration. Is this possible? I can’t surface anything via Google, and GPT-4 says its not possible.

If this is not possible, it definitely should be. I’d have thought being able to safely run arbitrary user code would be a big selling point of a platform like Workers.

If you set the usage model of the Worker to Standard you can also add a CPU limit:

You can’t limit overall duration but on the Standard usage model you are only billed for CPU time so it shouldn’t impact cost.

1 Like

Oh, thanks! I’ll just use that + a client-side abort for duration.

1 Like

Oh, actually, it looks like this whole “safely execute user code” use case it not possible on Cloudflare Workers. Just tried it and I get this:

I guess I’ll have to use Deno Deploy, which explicitly advertises this use case as part of its value prop.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.