> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cowboy.inc/llms.txt
> Use this file to discover all available pages before exploring further.

# What actor code can and can't do

> The imports actor code may use, why it has no files or network, and how to get the time, randomness and big numbers safely

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:

| Import | What `cowboy check` says |
| - | - |
| `os`, `socket`, `subprocess`, `threading`, `datetime`, `pickle` | `forbidden import 'os': non-deterministic or sandbox-escaping; rejected by the PVM import guard at runtime` |
| `asyncio`, `io`, `copy`, `uuid`, `decimal`, `fractions`, `statistics`, `urllib.request` | `import of decimal is not in the actor environment` |
| `time`, `random` | A warning. Use `runtime` instead, as below |

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](https://docs.cowboy.inc/developers/submitting-jobs.md)). For files, it's a volume attached to an off-chain function or a job ([An actor's files](https://docs.cowboy.inc/build/sdk/files.md)). And a library actor code can't import can run in an [off-chain function](https://docs.cowboy.inc/build/where-your-code-runs.md#off-chain-functions).

## 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:

```python theme={"system"}
from cowboy_sdk import Actor, public, runtime


class ClockActor(Actor):
    @public
    def now(self, _payload: object) -> object:
        return {
            "ms": runtime.get_timestamp_ms(),
            "roll": runtime.randomness(b"dice")[0] % 6 + 1,
        }
```

`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](https://docs.cowboy.inc/build/sdk/schedule.md)).

## 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

* [Determinism and sandbox](https://docs.cowboy.inc/architecture/actor-vm/determinism-and-sandbox.md)
* [PVM reference](https://docs.cowboy.inc/architecture/actor-vm/pvm-reference.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.