Most of the agent code I read is Python. LangChain apps, eval harnesses, a notebook someone turned into a service over a weekend. Most of the Sandscale examples I've written so far are TypeScript. That mismatch has bugged me for a while, so this one is for the Python people.
The sandscale package is on PyPI. It has one dependency (httpx) and needs Python 3.10 or later. I'm going to walk through the smallest useful thing you can do with it: start a box, run a command, get the output back, and make sure the box goes away. Nothing clever. The point is the shape, because the shape is what ends up copied into your agent's tool.
Disclosure, since it matters: I'm a founding member of Sandscale. Everything below comes from the package README on PyPI. Our docs site hasn't fully caught up with the Python SDK yet, so I'm linking PyPI instead of the docs.
Install, and where the key goes
pip install sandscale The client reads SANDSCALE_API_KEY from the environment. Put it there. Not in the code, and nowhere the model can see it. If your API key ever lands in a prompt or a tool result, assume it'll get printed back to someone eventually.
The whole thing
This is the quick start from the README, unchanged:
import sys from sandscale import Sandscale with Sandscale() as sandscale: # SANDSCALE_API_KEY from the environment box = sandscale.sandboxes.create(template="builtin:python", timeout_seconds=600) try: run = sandscale.sandboxes.run( box.id, 'python -c "print(6*7)"', region=box.region, on_stdout=sys.stdout.write, on_stderr=sys.stderr.write, ) print("exit code", run.exit_code) finally: sandscale.sandboxes.stop(box.id, region=box.region) A few of those lines do more work than they look like they do.
with Sandscale() as sandscale: The client is a context manager, and the with block closes it. That's about the client, not the box. Closing the client doesn't stop your sandbox, which is exactly why the finally is there.
template="builtin:python" picks a built-in image. The README lists them: base (the default), python, node, go, go_postgres and minimal. The one I didn't expect is go_postgres, which is Go with PostgreSQL 17 running inside the box and TEST_DATABASE_URL already set. If your agent writes code that talks to a database, a throwaway Postgres in the same box beats pointing it at anything shared.
timeout_seconds=600 is the backstop. If your script dies before finally runs, or the process gets killed, the box still stops on its own. I'd pick this per task instead of using one big number everywhere. Ten minutes is plenty for "run this snippet".
region=box.region shows up on every call after create. The box remembers which region it was made in, and you hand that back. It feels fussy the first time. By the third call you stop noticing.
on_stdout=sys.stdout.write streams output while the command runs, and you still get the exit code at the end. Without the callbacks, run waits and hands you a finished result with stdout, stderr and exit_code. If a person is watching a terminal, stream. If the output is going back to a model, I usually want the finished result so I can trim it first.
finally: ... stop(...) is the line I care about most. Whatever creates the box owns stopping it. Every time.
Wrapping it as an agent tool
Here's roughly how I'd turn that into a tool. The model hands me code, and I hand back something short it can reason about.
import shlex from sandscale import Sandscale MAX_CHARS = 4000 # how much output I'm willing to put back in context def run_python(code: str) -> dict: with Sandscale() as sandscale: box = sandscale.sandboxes.create(template="builtin:python", timeout_seconds=300) try: run = sandscale.sandboxes.run( box.id, f"python -c {shlex.quote(code)}", region=box.region ) finally: sandscale.sandboxes.stop(box.id, region=box.region) return { "exit_code": run.exit_code, "timed_out": run.timed_out, "oom_killed": run.oom_killed, "stdout": run.stdout[-MAX_CHARS:], "stderr": run.stderr[-MAX_CHARS:], } Two choices in there are worth arguing about.
I keep the tail of the output, not the head. When Python fails, the useful part (the traceback) is at the bottom. A model that only sees the first 4,000 characters of a long log will confidently fix the wrong thing.
I also pass timed_out and oom_killed through as their own fields. The result object has both, and they matter. "Your code ran out of memory" and "your code had a bug" need different next steps, and a model can't tell them apart from an empty stdout.
This version starts a fresh box for every call. It's the simplest thing that's obviously safe: no state leaks from one call to the next. The cost is that nothing carries over either, so variables, files and installed packages are gone each time. If your agent works in steps that build on each other, keep one box for the session and stop it when the session ends. I'd still start with one box per call and only change it once it actually hurts.
When pip install is the slow part
If every run starts with installing the same requirements, the README has a cache for that. This assumes your requirements.txt is already in /workspace inside the box:
r = sandscale.sandboxes.restore_cache(box.id, ecosystem="pip", lockfile="/workspace/requirements.txt") if not r.hit: sandscale.sandboxes.run(box.id, "pip install -r /workspace/requirements.txt") sandscale.sandboxes.save_cache(box.id, ecosystem="pip", lockfile="/workspace/requirements.txt") The server keys the cache from the lockfile it reads in the box, and the cache is shared within your organization only.
What this doesn't fix
A separate box keeps the code off your laptop and away from your other work. It doesn't make the code correct. It doesn't decide what the box can reach, either. Network access follows your plan and your organization's policy, so look at that before you assume anything.
It also won't stop a model from burning hours in a retry loop. A box counts for the whole time it runs, busy or idle. Only paused and stopped boxes are free. The timeout and the finally are what keep that honest, which is why I keep going on about them.
If you want to try this against a real account, there's a free two-week Pro trial when you sign up at sandscale.dev with a work email and set up an organization for your company.
Python folks: do you give your agent a fresh box per tool call, or one per session? I keep going back and forth, and I'd like to hear what made you pick one.

