# How to run Redis in a cloud sandbox Install redis-server with apt in an Ubuntu 24.04 microVM, check it with redis-cli ping, and connect to 127.0.0.1:6379 from the sandbox. **On Runtime, a paused sandbox keeps Redis's dataset in memory with no persistence configured.** A pause saves the machine's memory and running processes, so a cache, a queue or an agent's scratch state is there, unchanged, when the sandbox wakes, for up to 365 days. Every sandbox is a Firecracker microVM with its own kernel, so a test that runs `FLUSHALL` touches only its own server. An 8 GiB sandbox holding a large dataset costs $0.06125 an hour while nothing queries it: memory at $0.0075 a GiB-hour plus the 50-millicore CPU floor ([pricing](/docs/pricing)). ## Versions on 25 September 2026 | Source | Redis version | Install | | -------------------------------------------- | ---------------------------------------------------------------- | -------------------------------------------------------- | | Ubuntu 24.04 (`redis-server`) | 7.0.15 | `sudo apt-get install -y redis-server` | | Redis's apt repository (`packages.redis.io`) | 8.6.1 | add the repository, then `sudo apt-get install -y redis` | | Clients | redis-py 8.1.0 on PyPI; `redis` 6.2.1 and `ioredis` 6.0.0 on npm | `pip install`, `npm install` | ## Start Redis and use it The package installs a service, and Redis's own documentation says it starts after installation and at boot. The samples ask it to answer before going on, and start it if it has not. ```ts check import { Sandbox } from "withruntime"; await using sbx = await Sandbox.create({ timeoutSeconds: 1800 }); await sbx.exec("sudo apt-get update -qq && sudo apt-get install -y -qq redis-server", { check: true, timeoutMs: 600_000, }); await sbx.exec("redis-cli ping | grep -q PONG || sudo systemctl start redis-server", { check: true, }); await sbx.exec("pip install --quiet redis==8.1.0", { check: true, timeoutMs: 300_000 }); await sbx.files.write( "/workspace/worker.py", [ "import redis", "r = redis.Redis(decode_responses=True)", "for n in range(1, 6):", " r.rpush('jobs', f'job-{n}')", "done = [r.lpop('jobs') for _ in range(r.llen('jobs'))]", "print(len(done), 'jobs processed')", ].join("\n"), ); const run = await sbx.exec("python3 worker.py", { check: true }); console.log(run.stdout); console.log((await sbx.exec("redis-cli info memory | grep used_memory_human")).stdout); ``` ```python check from withruntime import Sandbox with Sandbox.create(timeout_seconds=1800) as sbx: sbx.exec("sudo apt-get update -qq && sudo apt-get install -y -qq redis-server", check=True, timeout_ms=600_000) sbx.exec("redis-cli ping | grep -q PONG || sudo systemctl start redis-server", check=True) sbx.exec("redis-cli set greeting hello", check=True) print(sbx.exec("redis-cli get greeting", check=True).stdout) # hello sbx.exec("redis-cli --rdb /workspace/dump.rdb", check=True) # a point-in-time copy sbx.files.download("/workspace/dump.rdb", "dump.rdb") ``` `redis-cli --rdb` transfers an RDB dump from the server to a file the sandbox user owns, so the data can go home with you or into another Redis. Code in the sandbox reaches the server on `127.0.0.1:6379`; nothing on the internet can connect in to a sandbox unless you open a way in. ## Redis 8 from Redis's own repository Redis's install guide for Ubuntu adds its signed repository. `lsb_release -cs` prints `noble` on a sandbox: ```bash no-run sudo apt-get install -y lsb-release curl gpg curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg sudo chmod 644 /usr/share/keyrings/redis-archive-keyring.gpg echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list sudo apt-get update && sudo apt-get install -y redis ``` It downloads over HTTPS, which the free trial allows. If Redis does not answer afterwards, the guide's fix is `sudo systemctl enable redis-server` and `sudo systemctl start redis-server`. ## Park it, wake it, find the data still there ```ts check import { Sandbox } from "withruntime"; const cache = await Sandbox.getOrCreate("agent-cache", { image: "redis", idlePauseSeconds: 600 }); await cache.exec("redis-cli set last-run $(date +%s)", { check: true }); // Ten quiet minutes later the sandbox pauses by itself; billing moves to storage. // Tomorrow, from any process: const again = await Sandbox.getOrCreate("agent-cache"); console.log((await again.exec("redis-cli get last-run")).stdout); ``` `getOrCreate` answers the sandbox that holds the name, woken if paused, so the same call works the first time and every time after. The `redis` image is built in the last section. A wake usually takes about half a second, and a paused sandbox is billed as storage: $0.08 per GB a month for the disk and memory it alone holds ([pause and resume](/how-to/pause-and-resume-a-sandbox)). ## Inspect it from your machine ```bash no-run runtime sandbox port-forward agent-cache 16379:6379 redis-cli -p 16379 monitor ``` RedisInsight or any client connects to `127.0.0.1:16379` the same way. The forward goes through Runtime's API with your key and works on the free trial ([forward ports](/docs/editors#forward-ports)). The same call exists in the SDKs as `sbx.forwardPort(6379)` and `sbx.forward_port(6379)`. ## Redis in every sandbox Build it into a [custom image](/docs/images) and the service starts with each sandbox made from it: ```ts check import { Runtime } from "withruntime"; const runtime = new Runtime(); await runtime.images.build({ name: "redis", recipe: { apt: ["redis-server"], pip: ["redis==8.1.0"] }, }); await using sbx = await runtime.sandboxes.create({ image: "redis", memoryMiB: 8192 }); ``` ```python check from withruntime import Runtime runtime = Runtime() runtime.images.build(name="redis", recipe={"apt": ["redis-server"], "pip": ["redis==8.1.0"]}) sbx = runtime.sandboxes.create(image="redis", memory_mib=8192) ``` A sandbox gets the memory you ask for. Redis holds its data in that memory, so size `memoryMiB` for the dataset and keep Redis's `maxmemory` below it. The free trial allows up to 4 GiB per sandbox. For Redis next to Postgres and your API, see [Docker Compose integration tests](/integrations/docker-compose); for a database with a disk that outlives sandboxes, see [PostgreSQL in a sandbox](/integrations/postgres). ## Sources - Redis, install on Ubuntu with APT, https://redis.io/docs/latest/operate/oss_and_stack/install/install-stack/apt/, read 25 September 2026 - Ubuntu 24.04 redis-server package, https://packages.ubuntu.com/noble/redis-server, read 25 September 2026 - PyPI redis, https://pypi.org/project/redis/, and npm, https://registry.npmjs.org/redis and https://registry.npmjs.org/ioredis, read 25 September 2026 Facts on this page were checked on 25 September 2026.