Skip to content
Guides · Agent cookbook

How Do I Keep a Webhook or Chat Bot Agent Running 24/7 in a Sandbox?

Updated November 18, 2026 .md

Short answer: Run the bot as an enabled systemd unit with Restart=always, and create the sandbox with --no-auto-stop. Then pick the idle setting by how the bot gets messages. A webhook bot can keep idle pause on, because a request to its URL woke ours in about 1 second. A bot on an outbound connection needs sbx idle 0.

This page is about a bot that waits for events: a chat message, a slash command, a GitHub delivery. Each event triggers a few tool calls. For an agent that works through a queue of long tasks, see resume a long-running agent after a crash. For splitting risky work off to throwaway sandboxes, see always-on agent with sandboxes for risky tasks.

We ran everything below on prod on 2026-11-18, in one small sandbox. The "agent" is a short Python webhook bot standing in for a real one. Each event runs one tool (df) and replies. No model was called. The bot's code doesn't change any of the results: they come from systemd and the sandbox.

Pick the settings by how the bot hears about messages#

Chat platforms deliver events in one of two ways, and the two need different settings.

The bot gets events by Examples Auto-stop Idle pause Why
An inbound HTTPS request (webhook) Slack Events API with a request URL, a Discord Interactions Endpoint URL, GitHub webhooks --no-auto-stop Can stay on A request to the sandbox's private hosted URL wakes it. We measured about 1 s
An outbound connection it holds open Slack Socket Mode, a Discord Gateway connection, long polling --no-auto-stop sbx idle <id> 0 No request ever reaches the sandbox, so nothing wakes it. While it's paused, the bot is frozen

Slack documents both options: "you can either use Socket Mode or you can designate a public HTTP endpoint" (Events API). Discord says an app receives interactions either over the Gateway or through an outgoing webhook, and that the two methods "are mutually exclusive" (receiving and responding).

The settings that can stop it, exactly#

All of these come from /docs/long-running, /docs/billing and /docs/snapshots.

Setting Default 24/7 value Field on the sandbox
Auto-stop (a hard deadline) 1 hour sbx new --no-auto-stop, or sbx extend <id> --no-auto-stop. The API takes "ttlSeconds": null. A deadline can be up to 30 days archiveAfter (null = never)
Idle auto-pause (a stop with memory) 30 minutes on the $20 plan, 60 on $100 and $500, 120 on $2,000 sbx idle <id> 0 (never), or keep it on for a webhook bot. The most is 10080 (7 days) idleStopMinutes, lastActivityAt
Wake on use Only after an idle pause A hosted URL holds a request while the sandbox wakes, for up to 45 s, then answers 503 with Retry-After. A private port wakes only for a request that carries its token state
  • Billing: metering is per second while the sandbox runs. A paused or stopped sandbox bills no compute. Its disk and memory image count toward your plan's included storage.
  • What doesn't wake by itself: a sandbox stopped by you, by auto-stop or by billing. Resume it.
  • Keeping a stopped one: /docs/snapshots says: "A stopped sandbox keeps its disk, memory and automatic snapshots for 14 days after it last stopped, at no charge."
  • No SLA: Sandboxer has no SLA during early access. If an event must never be lost, rely on the platform's retries, or put a queue in front of the bot.

1. Create the sandbox#

sbx new --name my-bot --type small --no-auto-stop --idle 0
sbx info sb_rr5058i7cp --json | jq -c '.sandbox|{state,type,archiveAfter,idleStopMinutes,memoryRestored,resumeReason}'
{"state":"ready","type":"small","archiveAfter":null,"idleStopMinutes":0,"memoryRestored":null,"resumeReason":null}

archiveAfter: null means no deadline, and idleStopMinutes: 0 means it never pauses. For a webhook bot you can set an idle timeout later with sbx idle <id> <minutes>, which is what we did in step 4.

2. Run the bot as a systemd unit#

The stand-in bot. It's a webhook receiver that runs one tool per event:

# /home/user/bot/bot.py — stand-in for a webhook-driven agent
import json, os, subprocess, time
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer

LOG = "/home/user/bot/events.log"

class Bot(BaseHTTPRequestHandler):
    def do_POST(self):
        body = self.rfile.read(int(self.headers.get("Content-Length", 0)) or 0)
        event = json.loads(body or b"{}")
        # the "tool": a shell command the agent is allowed to run
        tool = subprocess.run(["df", "-h", "--output=avail", "/"], capture_output=True, text=True).stdout.split()[-1]
        reply = {"ok": True, "got": event.get("text"), "tool": tool, "pid": os.getpid()}
        with open(LOG, "a") as f:
            f.write(f"{time.strftime('%H:%M:%S')} {json.dumps(event)}\n")
        out = json.dumps(reply).encode()
        self.send_response(200)
        self.send_header("Content-Type", "application/json")
        self.send_header("Content-Length", str(len(out)))
        self.end_headers()
        self.wfile.write(out)

    def log_message(self, *a):
        pass

ThreadingHTTPServer(("0.0.0.0", 8080), Bot).serve_forever()

The unit file:

# /etc/systemd/system/bot.service
[Unit]
Description=Webhook bot (stand-in for an agent)
After=network-online.target
Wants=network-online.target

[Service]
User=user
WorkingDirectory=/home/user/bot
ExecStart=/usr/bin/python3 -u /home/user/bot/bot.py
Restart=always
RestartSec=2

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now bot

enable makes it start on every boot, and Restart=always brings it back when it dies. Next, kill it the hard way:

sudo kill -9 $(systemctl show -p MainPID --value bot)
sleep 3
systemctl show -p MainPID -p NRestarts bot
sudo journalctl -u bot --no-pager -n 4 -o short-iso
MainPID=783
NRestarts=1
2026-11-18T17:54:48+00:00 tame-velvet-buffalo systemd[1]: bot.service: Main process exited, code=killed, status=9/KILL
2026-11-18T17:54:48+00:00 tame-velvet-buffalo systemd[1]: bot.service: Failed with result 'signal'.
2026-11-18T17:54:50+00:00 tame-velvet-buffalo systemd[1]: bot.service: Scheduled restart job, restart counter is at 1.
2026-11-18T17:54:50+00:00 tame-velvet-buffalo systemd[1]: Started bot.service - Webhook bot (stand-in for an agent).

The PID went from 771 to 783, and the bot was back 2 seconds later, which is RestartSec=2. A bot is a server, so it should never stay down, even after a clean exit. That's why we use Restart=always here, not on-failure.

3. Give it an HTTPS URL for the webhook#

sbx host sb_rr5058i7cp 8080 --title bot --json | jq -r .url
https://tame-velvet-buffalo-8080.box.sandboxer.com?_token=…

We saved that full URL as BOT_URL and never printed it.

From a laptop, first without the token and then with it:

curl -s -o /dev/null -w '%{http_code}\n' -X POST https://tame-velvet-buffalo-8080.box.sandboxer.com -d '{"text":"x"}'
curl -s -w '\n%{http_code} %{time_total}s\n' -X POST "$BOT_URL" -H 'Content-Type: application/json' -d '{"text":"deploy failed on main"}'
401
{"ok": true, "got": "deploy failed on main", "tool": "13G", "pid": 783}
200 0.297141s

Paste the full URL, token included, into the platform's webhook or request URL field. Treat it like a password. The token is removed before the request reaches your app, so your bot still has to verify the platform's own request signature. The subdomain stays the same across stop, resume and resize, so you only register the URL once.

4. Let it pause, then wake it with a webhook#

To test pausing quickly, we turned on a 1-minute idle timeout. We also started a second unit, beat, which stands in for a bot that holds an outbound connection. Every 15 seconds it makes an outbound HTTPS request and logs ok.

sbx idle sb_rr5058i7cp 1

The last activity was at 17:55:14, and the sandbox paused at 17:57:01 (state: archived, stop.reason: "idle"). Neither unit kept it awake, because neither one is activity that the sandbox counts. Then we sent a webhook from outside, with the token:

Wake Webhook answered Same bot PID?
1 200 in 1.005 s Yes (783)
2 200 in 0.996 s Yes
3 200 in 1.119 s Yes
4 200 in 0.997 s Yes
5 200 in 0.915 s Yes

The awake baseline was 0.30 s, so a wake added about 0.6 to 0.8 s. After each wake, memoryRestored was true. The request was held during the wake, not dropped, and the bot answered it. A request without the token while the sandbox was paused got 503 ("Sandbox is not running") in 0.19 s, and the sandbox stayed paused.

The beat log shows what an outbound-connection bot sees:

17:56:42 ok
17:56:57 ok
17:57:58 ok

Nothing ran for the minute it was paused. A real Socket Mode or Gateway bot would lose its connection in that time and miss every message until something woke the sandbox. So for that kind of bot, set sbx idle <id> 0.

Does about 1 second fit the platform's deadline?#

Slack says your app "should respond to the event request with an HTTP 2xx within three seconds." When it doesn't, Slack retries three times: almost at once, after 1 minute and after 5 minutes (Events API). For interactions, Discord says you "must send an initial response within 3 seconds" (receiving and responding). A wake of about 1 second leaves about 2 seconds for your code. So acknowledge first, then do the agent's slow work in the background: model calls and tool runs. The webhook request itself resets the idle clock, so work that finishes well inside the idle timeout is safe. For longer work, touch ~/.sandboxer/keep-awake while it runs and delete the file when it's done.

5. Stop, resume and cold boot: does the bot come back?#

We set sbx idle <id> 0 again, then stopped and resumed the sandbox:

sbx stop sb_rr5058i7cp --wait
sbx resume sb_rr5058i7cp

The same sbx info query as in step 1 then showed:

{"state":"ready","type":"small","archiveAfter":null,"idleStopMinutes":0,"memoryRestored":true,"resumeReason":null}

Both units kept their PIDs (783 and 891), and the next webhook got 200 from PID 783. Nothing restarted, because memory was restored.

A resume doesn't always restore memory. If no machine with the same CPU type is free in time, the sandbox boots from disk instead. To force that, we resumed onto a bigger size:

sbx stop sb_rr5058i7cp --wait
sbx resume sb_rr5058i7cp --type default

Then sbx info showed:

{"state":"ready","type":"default","archiveAfter":null,"idleStopMinutes":0,"memoryRestored":false,"resumeReason":"resized"}

Both units were running again under new PIDs (270 and 269), started by systemd at boot. The webhook URL answered 200 0.34 s after sbx resume returned. After every resume, memoryRestored and resumeReason say which kind you got. An enabled unit covers both kinds. Moving to a bigger size raises the hourly rate, so we did it only to force the cold boot. Which way of starting a service survives resume, reboot and kill compares the other start methods.

What it costs to run 24/7#

Prices are from /pricing. A small sandbox costs $0.018 an hour of running time, metered per second.

  • Always on (outbound-connection bot): /pricing counts a month as 730 hours, and 730 × $0.018 = $13.14 of machine time a month.
  • Webhook bot that's awake 4 hours a day for 30 days: 120 h × $0.018 = $2.16 of machine time. Each event keeps it awake for at least the idle timeout, so the awake time depends on how your events are spread out.

Plans start at $20/mo, and each plan includes a month of machine time equal to its price, so both of these fit inside the smallest plan's included time. You pay the plan price, not the plan price plus these amounts. Included time doesn't roll over (billing).

FAQ#

Does my bot process keep the sandbox from pausing?#

No. A systemd service is not activity: both of ours were running when the sandbox paused. Requests to its hosted URL, API calls that reach the VM, a 1-minute load average of at least 0.5, or a ~/.sandboxer/keep-awake file keep it awake. To never pause, use sbx idle <id> 0.

Will a webhook wake a sandbox I stopped myself?#

No. Wake on use only applies to a sandbox that paused itself for being idle. One that was stopped by you, by auto-stop or by billing stays stopped until you run sbx resume.

Does the webhook URL change after a resume?#

No. The subdomain stays the same across stop, resume and resize. Switching the port between private and public does change the URL you give the platform: --public clears the token, and --private mints a new one.

Is there an uptime guarantee for a 24/7 bot?#

No. Sandboxer has no SLA during early access. Design for gaps: answer fast, let the platform retry, and make your handlers safe to run twice.

More guides

Top AI sandbox platforms for code execution in 2026, ranked

For running AI-written code we rank Sandboxer, Freestyle and E2B first: each gives code its own VM with an API or SDK and can pause with memory. Pick Daytona for Windows or GPUs, Modal or Northflank for GPUs at scale, E2B or Northflank to run in your own cloud, and Vercel Sandbox if your app lives on Vercel.

Read the guide
Best sandboxes for running coding agents (Claude Code, Codex, Gemini CLI) in 2026, ranked

For coding agents we rank Sandboxer first: a full Ubuntu VM with Claude Code and Codex preinstalled, Docker, and stop-and-resume that keeps the agent's session in memory. Freestyle and Amp Orbs also keep memory across pauses. Pick E2B for prebuilt agent templates on open source, Docker Sandboxes for free local runs, and Codespaces if you live in GitHub.

Read the guide
Best Daytona sandbox alternatives in 2026, ranked

The best Daytona alternatives depend on why you're switching. For a full Linux microVM on every sandbox with memory-saving stop and Docker, we rank Sandboxer first. E2B suits open source and self-hosting, Modal massive short-job fleets, Northflank bring-your-own-cloud with GPUs, and Vercel Sandbox apps on Vercel.

Read the guide
Best E2B alternatives in 2026, ranked

If you're leaving E2B for longer sessions or a fuller machine, we rank Sandboxer first, then Freestyle: both give each sandbox a full Linux VM that keeps memory across pauses, with Docker and no short session cap. Pick Daytona for Windows or GPUs, Northflank for bring-your-own-cloud, and stay on E2B if you need open source.

Read the guide