Secrets
Code in a sandbox, or an agent driving it, shouldn’t be able to read your tokens. A Daytona secret solves that: the sandbox sees a placeholder in its environment, and Daytona’s egress proxy swaps in the real value only on requests to the hosts the secret names. The value never enters the sandbox.
The sandbox sees only a placeholder
Section titled “The sandbox sees only a placeholder”Declare a secret for some hosts
Section titled “Declare a secret for some hosts”import * as Daytona from "@alchemy.run/daytona";import * as Config from "effect/Config";
export const NpmToken = Daytona.Secret("NpmToken", { value: Config.Redacted("NPM_TOKEN"), hosts: ["registry.npmjs.org"],});Leave out hosts and Daytona sends the value to any host.
Give it to a sandbox
Section titled “Give it to a sandbox”import * as Daytona from "@alchemy.run/daytona";import { Base } from "./Images.ts";import { NpmToken } from "./Secrets.ts";
export const DevBox = Daytona.Sandbox("DevBox", { snapshot: Base, secrets: { NPM_TOKEN: NpmToken },});$NPM_TOKEN in the sandbox holds the placeholder, and npm install from a private registry works. Changing the secrets updates the sandbox in place.
Create a secret per user
Section titled “Create a secret per user”A Worker can create a secret per user and hand it to that user’s sandbox:
const secrets = yield* Daytona.CreateSecret();const github = yield* secrets.put({ name: `github-${user}`, value: token, hosts: ["api.github.com"] });const sandbox = yield* sandboxes.create({ secrets: [{ GITHUB_TOKEN: github.name }] });The Worker’s key has manage:secrets. Putting the same name again replaces the value. Each secret the binding creates carries stack/stage/id in its description, and is not deleted when the stack is destroyed: secrets.list() and match the description to clean them up.
Pull values from a secrets manager
Section titled “Pull values from a secrets manager”.env is only the default. A Stack’s secrets option reads the same Config values from a secrets manager instead, like Doppler or Infisical, so production tokens never sit in a file on anyone’s machine. Pick the source per stage:
import * as Cloudflare from "@alchemy.run/cloudflare";import * as Daytona from "@alchemy.run/daytona";import * as Doppler from "@alchemy.run/doppler";import * as Alchemy from "alchemy";import * as Effect from "effect/Effect";import * as Layer from "effect/Layer";import { DevBox } from "./src/DevBox.ts";
export default Alchemy.Stack( "Sandboxes", { providers: Layer.mergeAll(Cloudflare.providers(), Daytona.providers()), secrets: ({ stage }) => stage === "prod" ? Doppler.Secrets({ project: "sandboxes", config: "prd" }) : Alchemy.Secrets.DotEnv(), }, Effect.gen(function* () { const devBox = yield* DevBox; return { devBox: devBox.sandboxId }; }),);Your code doesn’t change: Config.Redacted("NPM_TOKEN") reads from whichever source the stage uses. See Secret providers for Doppler, Infisical, ordering several sources, and writing your own.
What a sandbox can reach at all is in Network and previews.