Giving daytona.io a spin

2025-07-03

Daytona is a cloud provider that seems to aim itself at the sandbox use-case. LLMs generate code that we can't always trust, so we'd like to run it in an environment that's safe and isolated. The whole point is to be able to run code that prints out the result that you're interested in. This is different from what modal because they will return full Python objects back.

First demo

The setup is straightforward, you grab an API key and you're able to run scripts like this:

import os
from daytona import Daytona, DaytonaConfig
from dotenv import load_dotenv


load_dotenv(".env")
# Define the configuration
config = DaytonaConfig(api_key=os.getenv("DAYTONA_API_KEY"))

# Initialize the Daytona client
daytona = Daytona(config)

# Create the Sandbox instance
sandbox = daytona.create()

# Run the code securely inside the Sandbox
response = sandbox.process.code_run('''
print("Hello World from code!")
''')
if response.exit_code != 0:
  print(f"Error: {response.exit_code} {response.result}")
else:
    print(response.result)

Custom environment

Daytona comes with a sensible default environment but you can also make your own.

# Define the dynamic image
dynamic_image = (
    Image.debian_slim("3.12")
    .pip_install(["pytest", "pytest-cov", "mypy", "ruff", "black", "gunicorn"])
    .run_commands("apt-get update && apt-get install -y git curl", "mkdir -p /home/daytona/project")
    .workdir("/home/daytona/project")
    .env({"ENV_VAR": "My Environment Variable"})
    .add_local_file("file_example.txt", "/home/daytona/project/file_example.txt")
)

# Resources to attach
resources = Resources(
    cpu=2,  # 2 CPU cores
    memory=4,  # 4GB RAM
    disk=8,  # 8GB disk space
)

# Create a new sandbox environment with the specs you want
sandbox = daytona.create(
    CreateSandboxFromImageParams(
        image=dynamic_image,
    ),
    timeout=0,
    resources=resources,
    on_snapshot_create_logs=print,
)

You are also able to use a Docker registry for your sandboxes if you prefer to define your dependencies that way.

More Features

The code looks and feels pretty similar to modal, but there are a few interesting differences. For starters, it seems that TypeScript is actually a first class citizen here, here, which makes a lot of sense since a lot of LLM apps are written in TypeScript. It certainly feels like a nice pattern to be able to call all something like Daytona from TypeScript, but still have access to all the tools in Python in a sandbox environment. I can definitely see that being useful.

I did spot another thing that seemed pretty nice, which is that you also have access to a terminal.

Uploaded image
One click and you're in.

Other features include git operations, adding volumes, bash commmands, log streaming and the ability to preview via urls. That last feature felt like a stellar one to try.

import os
from daytona import Daytona, DaytonaConfig
from dotenv import load_dotenv

load_dotenv(".env")
config = DaytonaConfig(api_key=os.getenv("DAYTONA_API_KEY"))
daytona = Daytona(config)

# Create the Sandbox instance, with public access
sandbox = daytona.create()
sandbox.public = True
preview_info = sandbox.get_preview_link(8000)
print(f"Preview link url: {preview_info.url}")
print(f"Preview link token: {preview_info.token}")

# Make a simple site to host
response = sandbox.process.exec("echo 'Hello World from a sandbox!' > index.html")

# Running that server
response = sandbox.process.exec("python -m http.server 8000", timeout=5)

This spins up a web server and also gives you a URL. Here's what mine looked like.

Uploaded image
It works!

This final feature feels particularly interesting because you could now have an LLM generate code inside of a sandbox, started up as a web server in the same secure sandbox and you would still be able to inspect it. Something about that feels like it might have legs to it.