cloudflare / cloudflare/agents

Feature Request: expose caller/session timezone inside Codemode sandbox execution

Open
#2,072 0 comments 0 reactions 1 assignee Claimed by @mattzcarey View on GitHub
enhancement
Dominant language
TypeScript
Stars
5.6k
Forks
711
Avg merge
1d 20h
Merged PRs (30d)
53

Description

## Problem

Codemode's sandboxed JS execution has no way to know the timezone of the
end-user/session driving the agent. `new Date()` inside the sandbox only
gives server/UTC time, with no IANA timezone context passed through from
`useAgent`/the calling session.

This breaks any date-boundary logic computed inside codemode (e.g. "today",
"this week") for users outside UTC: the sandbox's "today" is a UTC calendar
day (or a UTC-anchored rolling window), which can diverge from what the
end-user considers "today" in their own timezone — off by several hours
depending on time of day and offset.

## Request

Expose the caller's timezone (an IANA string, e.g. from `useAgent` config/
session) to the codemode sandbox — either:
- as a pre-run injected global/context value the sandboxed code can read, or
- as an option on the codemode execution call (e.g. `codemode.run(code, { timezone })`)

so date-boundary math done inside sandboxed code can be computed correctly
relative to the user's local calendar day instead of always UTC.

## Context

We hit this in production: an agent used codemode to compute a "today"
transaction window server-side (UTC-anchored), while our own frontend
computed "today" using the workspace's business timezone. The two disagreed
by a few hours around midnight UTC, producing different transaction counts
for what both surfaces called "today".

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.