Skip to content

Network and previews

Daytona controls a sandbox’s network from outside the sandbox, so nothing running inside it can turn the limits off. Two layers decide what goes out. Your organization’s tier sets the floor: below Tier 3, sandboxes reach only an allowlist of essential services, such as package registries, GitHub, AI APIs and Daytona’s own API, and from Tier 3 they reach the whole internet. On top of that, each sandbox can narrow it further.

Your tier sets the floor, each sandbox narrows it

Section titled “Your tier sets the floor, each sandbox narrows it”
git clonerefusedsandboxlimits enforced outsideelsewhereDevBoxdomainAllowListgithub.comallowedexample.comnot on the list
DevBox allows github.com and registry.npmjs.org. A clone from GitHub goes through; a connection to any host not on the list is refused before it leaves Daytona.
src/DevBox.ts
import * as Daytona from "@alchemy.run/daytona";
import { Base } from "./Images.ts";
export const DevBox = Daytona.Sandbox("DevBox", {
snapshot: Base,
domainAllowList: ["github.com", "registry.npmjs.org"],
});

Use networkAllowList for CIDR ranges, and networkBlockAll: true to cut the network entirely. All three change in place.

src/DevBox.ts
import * as Daytona from "@alchemy.run/daytona";
import { Base } from "./Images.ts";
export const DevBox = Daytona.Sandbox("DevBox", {
snapshot: Base,
domainAllowList: ["github.com", "registry.npmjs.org"],
outboundProxyUrl: "http://proxy.example.com:3128",
});

Daytona sets HTTP_PROXY and HTTPS_PROXY in the sandbox to this URL, and enforces it at the network only when the sandbox also has a domainAllowList. It’s a forward proxy: HTTPS requests reach it as CONNECT tunnels, so it runs on a host that accepts them, such as a Fly Machine. A Cloudflare Worker can’t serve CONNECT, so it can’t be one. The URL is in the sandbox’s environment, so the sandbox can read any password in it. To add a credential the sandbox never sees, use a Secret. Changing the URL replaces the sandbox.

const sandbox = yield* sandboxes.create({
domainAllowList: "api.openai.com,github.com",
networkBlockAll: false,
});
yield* sandbox.updateNetworkSettings({ domainAllowList: "github.com" });

create takes Daytona’s own request, so the lists are comma-separated strings here.

A preview URL reaches a port inside a sandbox through Daytona’s proxy. A private sandbox’s previews need its preview token in the X-Daytona-Preview-Token header; a public sandbox’s previews are open to anyone.

GET /Daytonasandboxprivateyour Workersends the tokenpreview URLDaytona proxyport 3000pnpm dev
A request reaches port 3000 only through the preview URL, and Daytona's proxy lets it through only with the sandbox's preview token. A public sandbox skips the check.
const preview = yield* sandbox.getPortPreviewUrl({ port: 3000 });
const signed = yield* sandbox.getSignedPortPreviewUrl({ port: 3000, expiresInSeconds: 3600 });
const port = yield* sandbox.getTcpPort(3000);
const res = yield* port.fetch(HttpClientRequest.get("/health"));

A signed URL works without the token until it expires, so you can hand it to a browser. getTcpPort returns the port’s preview url and token, and its fetch sends a request there with the token for you.

fetch also takes the request your Worker received, and returns a response the Worker can send straight back:

const port = yield* sandbox.getTcpPort(3000);
return yield* port.fetch(yield* HttpServerRequest);

The method, path, query, headers and body go to the sandbox’s server, and its status, headers and body come back. Bodies stream both ways.

src/DevBox.ts
import * as Daytona from "@alchemy.run/daytona";
import { Base } from "./Images.ts";
export const DevBox = Daytona.Sandbox("DevBox", { snapshot: Base, public: true });

public changes in place.

Credentials a sandbox can use but not read are in Secrets.