Skip to main content
This page tells you what actor code can use, and where to turn for what it can’t. The limits have one reason behind them: every call to an actor runs on many machines, and all of them must reach the same result. So actor code runs in a sandbox that allows only what gives the same answer everywhere. cowboy check and cowboy test both enforce these rules.

Imports

Actor code can import modules that only compute on data, such as json, re, hashlib, math and collections, and cowboy_sdk. Some imports are refused, because they reach outside the sandbox or vary from machine to machine: The PVM in that message is the Python interpreter that runs actors. If a module isn’t listed here, try it: cowboy check names any import it refuses.

No files, no network

Actor code can’t open a file or a connection, but it can hand that work to something that can. For a web API, model or tool, that’s a runner job (Call models, the web and tools). For files, it’s a volume attached to an off-chain function or a job (An actor’s files). And a library actor code can’t import can run in an off-chain function.

Time and randomness

Python’s own clock and random numbers would differ from machine to machine, so runtime provides versions that don’t. This handler returns the time and a dice roll:
runtime.get_timestamp_ms() is the current time, in milliseconds since 1970, the same on every machine. runtime.randomness(domain) returns random bytes every machine agrees on. Use a different domain for each purpose. The test mock doesn’t provide it, so try it with cowboy run. For delays and schedules, use schedule_after and @every, in seconds (An actor’s schedule).

Numbers and data

Numbers and data need a little care. Integers can’t exceed 4,096 bits: going past that raises OverflowError, and a larger constant fails cowboy check. Floats work, and give the same result on every machine, but for money, use whole numbers in base units. Sets have no fixed order, so use cowboy_sdk.ordered_set when order can affect the result. Module-level names hold fixed data only: numbers, strings, and lists or dicts of them. A computed value fails cowboy check, and anything that changes belongs in self.storage.

Next