From d3414b0ea639820a655e76d79bb7a85084f6e177 Mon Sep 17 00:00:00 2001 From: Dave Lucia Date: Sun, 31 May 2026 03:03:37 -0700 Subject: [PATCH 1/7] chore(A21a): start plan --- .agents/plans/A21a-os-library.md | 89 ++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 .agents/plans/A21a-os-library.md diff --git a/.agents/plans/A21a-os-library.md b/.agents/plans/A21a-os-library.md new file mode 100644 index 00000000..27f50bc5 --- /dev/null +++ b/.agents/plans/A21a-os-library.md @@ -0,0 +1,89 @@ +--- +id: A21a +title: "Implement the os standard library" +issue: 259 +pr: null +branch: fix/runtime-type-errors +base: main +status: in-progress +direction: A +unlocks: + - all.lua +--- + +## Goal + +Implement a sandbox-safe Lua 5.3 `os` standard library so code that +calls `os.clock`, `os.time`, `os.date`, etc. no longer raises a runtime +type error on a nil `os` global. + +## Context + +Sub-plan of the A21 triage cluster (parent +`.agents/plans/A21-triage-runtime-type-errors.md`, issue #259). Triage +of the four cluster files found: + +- `utf8.lua` — already passes; no work needed. +- `math.lua` — first runtime failure under suite config is `load()` + being sandboxed at line 277 (`checkcompt` → `assert(load(code))`); + this is a `load`/sandbox concern, out of scope here. +- `coroutine.lua` — `coroutine` global is nil; the whole coroutine + subsystem is unimplemented, far too large for this PR. +- `all.lua` — first runtime failure is `attempt to call a nil value + (field 'clock' on global 'os')` at line 57. The `os` library is not + implemented at all. + +The single most tractable concrete fix is the missing `os` library. + +## Out of scope + +- `coroutine.lua` and the coroutine subsystem. +- `math.lua` `load()` sandbox behaviour. +- Filesystem / subprocess os functions (`os.remove`, `os.rename`, + `os.execute`) beyond sandbox-safe stubs. +- Making `all.lua` fully pass — it is the suite harness and will + progress to the next failure (it loads other suite files). The skip + range is narrowed to reflect the new failure point. + +## Success criteria + +- [ ] New `Lua.VM.Stdlib.Os` module installed into the global env. +- [ ] `os.time`, `os.clock`, `os.difftime`, `os.date`, `os.getenv`, + `os.setlocale`, `os.tmpname`, `os.exit` implemented per Lua 5.3. +- [ ] Regression unit tests under `test/lua/vm/stdlib/`. +- [ ] `all.lua` skip range narrowed to its new (post-os) failure with a + precise reason. +- [ ] `mix test` and `mix test test/lua53_suite_test.exs --only lua53` + both green. + +## Implementation notes + +- Model the module on `lib/lua/vm/stdlib/math.ex` (behaviour + `Lua.VM.Stdlib.Library`, `lib_name/0`, `install/1`, native funcs of + arity 2 returning `{results, state}`). +- Register it in `lib/lua/vm/stdlib.ex` alongside the other libraries. +- `os.time` with a table arg builds a unix timestamp from the fields; + bare `os.time()` returns the current epoch seconds. +- `os.date` supports `*t` / `!*t` (table) and strftime-like format + strings; `!` selects UTC. +- `os.setlocale` is a no-op that returns "C" (sandbox has no locale). + +## Verification + +```bash +mix format +mix compile --warnings-as-errors +mix test +mix test test/lua53_suite_test.exs --only lua53 +``` + +## Risks + +- `os.date` format coverage is partial; only the directives the suite + and common code use are guaranteed. +- `all.lua` will not pass outright; the narrowed skip must land on a + syntactically valid boundary. + +## Discoveries + +(populated during implementation) From 9d30bd327d6587e51048adf111311c78460c641d Mon Sep 17 00:00:00 2001 From: Dave Lucia Date: Sun, 31 May 2026 03:07:47 -0700 Subject: [PATCH 2/7] feat(stdlib): implement the os standard library Add a sandbox-safe `os` library so Lua code that calls os.clock, os.time, os.date and friends no longer raises a runtime type error on a nil `os` global. Functions: os.time (current epoch or from a date table), os.clock, os.difftime, os.date (strftime-style formats plus *t / !*t broken-down tables, ! selecting UTC), os.getenv, os.setlocale (no-op reporting the C locale), os.tmpname, and os.exit. The high-level Lua API already listed os.getenv/os.exit/os.tmpname/os.execute/os.remove/os.rename in its default sandbox, so those stay blocked unless explicitly allowed. This unblocks the os section of the all.lua suite harness; the remaining harness body (dofile/loadfile/string.dump/coroutine.wrap and io.open post-run summary) stays skipped via narrowed line ranges. Plan: A21a Closes #259 --- lib/lua/vm/stdlib.ex | 1 + lib/lua/vm/stdlib/os.ex | 271 +++++++++++++++++++++++++++++++++ test/lua/vm/stdlib/os_test.exs | 65 ++++++++ test/lua53_skips.exs | 14 +- 4 files changed, 350 insertions(+), 1 deletion(-) create mode 100644 lib/lua/vm/stdlib/os.ex create mode 100644 test/lua/vm/stdlib/os_test.exs diff --git a/lib/lua/vm/stdlib.ex b/lib/lua/vm/stdlib.ex index ee6dcc33..e239e326 100644 --- a/lib/lua/vm/stdlib.ex +++ b/lib/lua/vm/stdlib.ex @@ -49,6 +49,7 @@ defmodule Lua.VM.Stdlib do |> install_library(Lua.VM.Stdlib.Math) |> install_library(Lua.VM.Stdlib.Table) |> install_library(Lua.VM.Stdlib.Utf8) + |> install_library(Lua.VM.Stdlib.Os) |> install_library(Lua.VM.Stdlib.Debug) |> preload_stdlib_modules() |> install_unpack_alias() diff --git a/lib/lua/vm/stdlib/os.ex b/lib/lua/vm/stdlib/os.ex new file mode 100644 index 00000000..ec1ae8e4 --- /dev/null +++ b/lib/lua/vm/stdlib/os.ex @@ -0,0 +1,271 @@ +defmodule Lua.VM.Stdlib.Os do + @moduledoc """ + Lua 5.3 `os` standard library (sandbox-safe subset). + + Provides time and date facilities plus a handful of environment + helpers. Functions that would touch the filesystem or spawn + subprocesses are intentionally absent or stubbed, since the VM runs in + an embedded sandbox. + + ## Functions + + - `os.time([table])` - Epoch seconds, optionally from a date table. + - `os.clock()` - Approximate CPU time used, in seconds. + - `os.difftime(t2, t1)` - Difference in seconds between two times. + - `os.date([format [, time]])` - Formats a time as a string or table. + - `os.getenv(name)` - Value of an environment variable, or nil. + - `os.setlocale([locale [, category]])` - No-op returning "C". + - `os.tmpname()` - A name usable for a temporary file. + - `os.exit([code [, close]])` - Raises to unwind; sandbox cannot exit. + """ + + @behaviour Lua.VM.Stdlib.Library + + alias Lua.VM.ArgumentError + alias Lua.VM.RuntimeError + alias Lua.VM.State + alias Lua.VM.Stdlib.Util + + @impl true + def lib_name, do: "os" + + @impl true + def install(state) do + os_table = %{ + "clock" => {:native_func, &os_clock/2}, + "date" => {:native_func, &os_date/2}, + "difftime" => {:native_func, &os_difftime/2}, + "exit" => {:native_func, &os_exit/2}, + "getenv" => {:native_func, &os_getenv/2}, + "setlocale" => {:native_func, &os_setlocale/2}, + "time" => {:native_func, &os_time/2}, + "tmpname" => {:native_func, &os_tmpname/2} + } + + {tref, state} = State.alloc_table(state, os_table) + State.set_global(state, "os", tref) + end + + # os.clock() — approximate CPU/elapsed time used, in seconds. + defp os_clock(_args, state) do + seconds = (:erlang.monotonic_time(:nanosecond) - boot_offset()) / 1_000_000_000 + {[seconds], state} + end + + # os.difftime(t2, t1) — t2 - t1 as a float number of seconds. + defp os_difftime([t2, t1 | _], state) when is_number(t2) and is_number(t1) do + {[(t2 - t1) / 1], state} + end + + defp os_difftime([t2 | _], state) when is_number(t2) do + {[t2 / 1], state} + end + + defp os_difftime([t2 | _], _state) do + raise ArgumentError.type_error("os.difftime", 1, "number", Util.typeof(t2)) + end + + defp os_difftime([], _state) do + raise ArgumentError.value_expected("os.difftime", 1) + end + + # os.time([table]) — current epoch seconds, or seconds for the given + # date table (fields: year, month, day, hour, min, sec, isdst). + defp os_time([], state) do + {[System.os_time(:second)], state} + end + + defp os_time([nil | _], state) do + {[System.os_time(:second)], state} + end + + defp os_time([{:tref, _} = tref | _], state) do + data = State.get_table(state, tref).data + + year = required_field(data, "year", "os.time") + month = required_field(data, "month", "os.time") + day = required_field(data, "day", "os.time") + hour = optional_field(data, "hour", 12) + min = optional_field(data, "min", 0) + sec = optional_field(data, "sec", 0) + + seconds = + naive_to_epoch(%{ + year: year, + month: month, + day: day, + hour: hour, + minute: min, + second: sec + }) + + {[seconds], state} + end + + defp os_time([arg | _], _state) do + raise ArgumentError.type_error("os.time", 1, "table", Util.typeof(arg)) + end + + # os.date([format [, time]]) — formats a time. + defp os_date([], state), do: os_date(["%c"], state) + defp os_date([nil | rest], state), do: os_date(["%c" | rest], state) + + defp os_date([format | rest], state) when is_binary(format) do + {format, utc?} = strip_utc_flag(format) + + time = + case rest do + [t | _] when is_number(t) -> trunc(t) + _ -> System.os_time(:second) + end + + dt = to_datetime(time, utc?) + + case format do + "*t" -> date_table(dt, state) + _ -> {[strftime(format, dt)], state} + end + end + + defp os_date([format | _], _state) do + raise ArgumentError.type_error("os.date", 1, "string", Util.typeof(format)) + end + + # os.getenv(name) — value of an environment variable, or nil. + defp os_getenv([name | _], state) when is_binary(name) do + {[System.get_env(name)], state} + end + + defp os_getenv([name | _], _state) do + raise ArgumentError.type_error("os.getenv", 1, "string", Util.typeof(name)) + end + + defp os_getenv([], _state) do + raise ArgumentError.value_expected("os.getenv", 1) + end + + # os.setlocale([locale [, category]]) — no locale support in the + # sandbox; report the "C" locale as active. + defp os_setlocale(_args, state), do: {["C"], state} + + # os.tmpname() — a name usable for a temporary file. + defp os_tmpname(_args, state) do + name = Path.join(System.tmp_dir() || "/tmp", "lua_#{:erlang.unique_integer([:positive])}") + {[name], state} + end + + # os.exit([code [, close]]) — the sandbox cannot terminate the host, so + # raise to unwind the current evaluation. + defp os_exit(_args, _state) do + raise RuntimeError, value: "os.exit is not supported in embedded mode" + end + + ## Helpers + + defp required_field(data, key, fn_name) do + case Map.get(data, key) do + n when is_number(n) -> + trunc(n) + + _ -> + raise RuntimeError, value: "field '#{key}' missing in date table for '#{fn_name}'" + end + end + + defp optional_field(data, key, default) do + case Map.get(data, key) do + n when is_number(n) -> trunc(n) + _ -> default + end + end + + defp naive_to_epoch(%{year: y, month: mo, day: d, hour: h, minute: mi, second: s}) do + {:ok, naive} = NaiveDateTime.new(y, mo, d, h, mi, s) + naive |> DateTime.from_naive!("Etc/UTC") |> DateTime.to_unix(:second) + end + + defp strip_utc_flag("!" <> rest), do: {rest, true} + defp strip_utc_flag(format), do: {format, false} + + defp to_datetime(time, _utc?) do + DateTime.from_unix!(time, :second) + end + + defp date_table(%DateTime{} = dt, state) do + yday = Date.day_of_year(DateTime.to_date(dt)) + # Lua wday: 1 = Sunday .. 7 = Saturday; Elixir: 1 = Monday .. 7 = Sunday. + wday = rem(Date.day_of_week(DateTime.to_date(dt)), 7) + 1 + + fields = %{ + "year" => dt.year, + "month" => dt.month, + "day" => dt.day, + "hour" => dt.hour, + "min" => dt.minute, + "sec" => dt.second, + "wday" => wday, + "yday" => yday, + "isdst" => false + } + + {tref, state} = State.alloc_table(state, fields) + {[tref], state} + end + + defp strftime(format, %DateTime{} = dt) do + Regex.replace(~r/%./, format, fn directive -> + directive_value(directive, dt) + end) + end + + defp directive_value("%Y", dt), do: Integer.to_string(dt.year) + defp directive_value("%y", dt), do: pad2(rem(dt.year, 100)) + defp directive_value("%m", dt), do: pad2(dt.month) + defp directive_value("%d", dt), do: pad2(dt.day) + defp directive_value("%H", dt), do: pad2(dt.hour) + defp directive_value("%M", dt), do: pad2(dt.minute) + defp directive_value("%S", dt), do: pad2(dt.second) + defp directive_value("%p", dt), do: if(dt.hour < 12, do: "AM", else: "PM") + defp directive_value("%A", dt), do: weekday_name(dt) + defp directive_value("%a", dt), do: String.slice(weekday_name(dt), 0, 3) + defp directive_value("%B", dt), do: month_name(dt) + defp directive_value("%b", dt), do: String.slice(month_name(dt), 0, 3) + defp directive_value("%j", dt), do: pad3(Date.day_of_year(DateTime.to_date(dt))) + + defp directive_value("%c", dt) do + "#{String.slice(weekday_name(dt), 0, 3)} #{String.slice(month_name(dt), 0, 3)} " <> + "#{pad2(dt.day)} #{pad2(dt.hour)}:#{pad2(dt.minute)}:#{pad2(dt.second)} #{dt.year}" + end + + defp directive_value("%x", dt), do: "#{pad2(dt.month)}/#{pad2(dt.day)}/#{pad2(rem(dt.year, 100))}" + defp directive_value("%X", dt), do: "#{pad2(dt.hour)}:#{pad2(dt.minute)}:#{pad2(dt.second)}" + defp directive_value("%%", _dt), do: "%" + defp directive_value(other, _dt), do: other + + @weekdays {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"} + @months {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", + "December"} + + defp weekday_name(%DateTime{} = dt) do + elem(@weekdays, Date.day_of_week(DateTime.to_date(dt)) - 1) + end + + defp month_name(%DateTime{} = dt), do: elem(@months, dt.month - 1) + + defp pad2(n), do: n |> Integer.to_string() |> String.pad_leading(2, "0") + defp pad3(n), do: n |> Integer.to_string() |> String.pad_leading(3, "0") + + # Monotonic clock origin captured at module load so os.clock() reports + # elapsed seconds from a stable reference. + defp boot_offset do + case :persistent_term.get({__MODULE__, :boot}, nil) do + nil -> + now = :erlang.monotonic_time(:nanosecond) + :persistent_term.put({__MODULE__, :boot}, now) + now + + offset -> + offset + end + end +end diff --git a/test/lua/vm/stdlib/os_test.exs b/test/lua/vm/stdlib/os_test.exs new file mode 100644 index 00000000..d122ac03 --- /dev/null +++ b/test/lua/vm/stdlib/os_test.exs @@ -0,0 +1,65 @@ +defmodule Lua.VM.Stdlib.OsTest do + use ExUnit.Case, async: true + + # Regression coverage for Lua 5.3 suite: all.lua line 57 + # (`local initclock = os.clock()`), which raised + # "attempt to call a nil value (field 'clock' on global 'os')" + # before the os library existed. + + describe "os library" do + test "os.clock returns a number" do + {[c], _} = Lua.eval!("return os.clock()") + assert is_number(c) + end + + test "os.time with no args returns current epoch seconds" do + {[t], _} = Lua.eval!("return os.time()") + assert is_integer(t) + assert t > 1_500_000_000 + end + + test "os.time builds an epoch from a date table (UTC)" do + code = "return os.time({year=2000, month=1, day=1, hour=0, min=0, sec=0})" + {[t], _} = Lua.eval!(code) + assert t == 946_684_800 + end + + test "os.difftime returns the difference in seconds" do + {[d], _} = Lua.eval!("return os.difftime(10, 3)") + assert d == 7.0 + end + + test "os.date formats with strftime directives" do + code = ~S[return os.date("!%Y-%m-%d", 946684800)] + {[s], _} = Lua.eval!(code) + assert s == "2000-01-01" + end + + test "os.date with *t returns a broken-down time table" do + code = """ + local t = os.date("!*t", 946684800) + return t.year, t.month, t.day, t.hour, t.min, t.sec + """ + + {[year, month, day, hour, min, sec], _} = Lua.eval!(code) + assert {year, month, day, hour, min, sec} == {2000, 1, 1, 0, 0, 0} + end + + test "os.setlocale reports the C locale" do + {[locale], _} = Lua.eval!(~S[return os.setlocale("C")]) + assert locale == "C" + end + + test "os.getenv returns nil for an undefined variable when not sandboxed" do + lua = Lua.new(sandboxed: []) + {[v], _} = Lua.eval!(lua, ~S[return os.getenv("LUA_NONEXISTENT_VAR_XYZ")]) + assert v == nil + end + + test "os.getenv is sandboxed by default" do + assert_raise Lua.RuntimeException, ~r/os\.getenv.*sandboxed/, fn -> + Lua.eval!(~S[return os.getenv("PATH")]) + end + end + end +end diff --git a/test/lua53_skips.exs b/test/lua53_skips.exs index 8e6322ff..28884895 100644 --- a/test/lua53_skips.exs +++ b/test/lua53_skips.exs @@ -30,7 +30,19 @@ %{ "all.lua" => [ - %{lines: :all, category: :unimplemented, reason: "upstream harness file, pending initial triage", issue: nil} + %{ + lines: 137..208, + category: :unimplemented, + reason: + "harness drives every other suite file via dofile/loadfile/string.dump/coroutine.wrap, none supported in the sandbox", + issue: 259 + }, + %{ + lines: 211..263, + category: :unimplemented, + reason: "post-run summary uses io.open and timing files unavailable in the sandbox", + issue: 259 + } ], "big.lua" => [ %{ From 402404a336f928b73a081adf2f9dfb40fe4d4458 Mon Sep 17 00:00:00 2001 From: Dave Lucia Date: Sun, 31 May 2026 03:08:26 -0700 Subject: [PATCH 3/7] chore(A21a): mark plan as review --- .agents/plans/A21a-os-library.md | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/.agents/plans/A21a-os-library.md b/.agents/plans/A21a-os-library.md index 27f50bc5..0a50f3bb 100644 --- a/.agents/plans/A21a-os-library.md +++ b/.agents/plans/A21a-os-library.md @@ -2,10 +2,10 @@ id: A21a title: "Implement the os standard library" issue: 259 -pr: null +pr: 289 branch: fix/runtime-type-errors base: main -status: in-progress +status: review direction: A unlocks: - all.lua @@ -86,4 +86,14 @@ mix test test/lua53_suite_test.exs --only lua53 ## Discoveries -(populated during implementation) +- The high-level `Lua` API already lists `os.getenv`, `os.exit`, + `os.tmpname`, `os.execute`, `os.remove`, `os.rename` in its + `@default_sandbox`, anticipating an os library. Those remain blocked + by default; the unit test pins that contract. +- `all.lua`'s harness `do ... end` block (63..209) wraps the dofile + redefinition, so the skip must keep the `do`/`end` balanced — hence + two ranges (137..208, 211..263) rather than one. +- After os lands, `all.lua` progresses to `attempt to call a number + value (upvalue 'report')` inside the dofile-redefinition closure — a + VM upvalue concern surfacing only through the unsupported + loadfile/string.dump path; left for a future coroutine/load pass. From 1c1a652bd8895ff6535df18b4c3db9d29533b6e9 Mon Sep 17 00:00:00 2001 From: Dave Lucia Date: Sun, 31 May 2026 03:46:48 -0700 Subject: [PATCH 4/7] fix(stdlib): make os.clock non-negative on first call os.clock computed monotonic_time - boot_offset(), but BEAM evaluates the left operand first while boot_offset() lazily seeds the origin a few ns later, producing a small negative value on the first call. Read the offset before the current time and clamp the elapsed value at zero. Pin the non-negative contract in the os.clock regression test, document that local time equals UTC in the timezone-less sandbox, and align the plan frontmatter issue with the issue this PR closes. Closes #280 --- .agents/plans/A21a-os-library.md | 2 +- lib/lua/vm/stdlib/os.ex | 11 +++++++++-- test/lua/vm/stdlib/os_test.exs | 3 ++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.agents/plans/A21a-os-library.md b/.agents/plans/A21a-os-library.md index 0a50f3bb..49c2b33f 100644 --- a/.agents/plans/A21a-os-library.md +++ b/.agents/plans/A21a-os-library.md @@ -1,7 +1,7 @@ --- id: A21a title: "Implement the os standard library" -issue: 259 +issue: 280 pr: 289 branch: fix/runtime-type-errors base: main diff --git a/lib/lua/vm/stdlib/os.ex b/lib/lua/vm/stdlib/os.ex index ec1ae8e4..acf5743e 100644 --- a/lib/lua/vm/stdlib/os.ex +++ b/lib/lua/vm/stdlib/os.ex @@ -46,9 +46,13 @@ defmodule Lua.VM.Stdlib.Os do State.set_global(state, "os", tref) end - # os.clock() — approximate CPU/elapsed time used, in seconds. + # os.clock() — approximate CPU/elapsed time used, in seconds. Reads the + # boot offset before the current time so the elapsed value is never + # negative on the first call (when the offset is seeded lazily). defp os_clock(_args, state) do - seconds = (:erlang.monotonic_time(:nanosecond) - boot_offset()) / 1_000_000_000 + offset = boot_offset() + elapsed_ns = :erlang.monotonic_time(:nanosecond) - offset + seconds = max(0, elapsed_ns) / 1_000_000_000 {[seconds], state} end @@ -187,6 +191,9 @@ defmodule Lua.VM.Stdlib.Os do defp strip_utc_flag("!" <> rest), do: {rest, true} defp strip_utc_flag(format), do: {format, false} + # The sandbox has no timezone database, so local time and UTC are + # treated as identical. The utc? flag is parsed for compatibility with + # the leading '!' but does not change the result. defp to_datetime(time, _utc?) do DateTime.from_unix!(time, :second) end diff --git a/test/lua/vm/stdlib/os_test.exs b/test/lua/vm/stdlib/os_test.exs index d122ac03..0b650708 100644 --- a/test/lua/vm/stdlib/os_test.exs +++ b/test/lua/vm/stdlib/os_test.exs @@ -7,9 +7,10 @@ defmodule Lua.VM.Stdlib.OsTest do # before the os library existed. describe "os library" do - test "os.clock returns a number" do + test "os.clock returns a non-negative number" do {[c], _} = Lua.eval!("return os.clock()") assert is_number(c) + assert c >= 0 end test "os.time with no args returns current epoch seconds" do From a030c90673c32f698772a0782e980a818c461195 Mon Sep 17 00:00:00 2001 From: Dave Lucia Date: Sun, 31 May 2026 05:00:02 -0700 Subject: [PATCH 5/7] chore(A43): rename os-library plan from A21a to A43 The os standard library was misfiled under plan id A21a during an interrupted batch; its true scope is issue #280. Rename to its own id A43 to avoid colliding with A21a-integer-divide-by-zero (#259). --- .agents/plans/{A21a-os-library.md => A43-os-library.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .agents/plans/{A21a-os-library.md => A43-os-library.md} (100%) diff --git a/.agents/plans/A21a-os-library.md b/.agents/plans/A43-os-library.md similarity index 100% rename from .agents/plans/A21a-os-library.md rename to .agents/plans/A43-os-library.md From 35b4dabeab4039a8ad3f71417cf3b22be3cdb575 Mon Sep 17 00:00:00 2001 From: Dave Lucia Date: Sun, 31 May 2026 05:01:46 -0700 Subject: [PATCH 6/7] chore(A43): set plan frontmatter id to A43 --- .agents/plans/A43-os-library.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.agents/plans/A43-os-library.md b/.agents/plans/A43-os-library.md index 49c2b33f..daa2c386 100644 --- a/.agents/plans/A43-os-library.md +++ b/.agents/plans/A43-os-library.md @@ -1,5 +1,5 @@ --- -id: A21a +id: A43 title: "Implement the os standard library" issue: 280 pr: 289 From 1685b4bb1c2b331e3a841fdc81c66b4fd069bb69 Mon Sep 17 00:00:00 2001 From: Dave Lucia Date: Sun, 31 May 2026 05:25:33 -0700 Subject: [PATCH 7/7] docs(stdlib): note future VFS migration for os.tmpname os.tmpname currently resolves against the host filesystem via System.tmp_dir/0. Once the VFS layer lands it should resolve against the sandboxed virtual filesystem so the VM never touches host paths. --- lib/lua/vm/stdlib/os.ex | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/lua/vm/stdlib/os.ex b/lib/lua/vm/stdlib/os.ex index acf5743e..c5ca5961 100644 --- a/lib/lua/vm/stdlib/os.ex +++ b/lib/lua/vm/stdlib/os.ex @@ -153,6 +153,10 @@ defmodule Lua.VM.Stdlib.Os do defp os_setlocale(_args, state), do: {["C"], state} # os.tmpname() — a name usable for a temporary file. + # + # FUTURE: this leans on the host filesystem via System.tmp_dir/0. Once the + # VFS layer lands we want tmpname to resolve against the sandboxed virtual + # filesystem instead of the real host, so the VM never touches host paths. defp os_tmpname(_args, state) do name = Path.join(System.tmp_dir() || "/tmp", "lua_#{:erlang.unique_integer([:positive])}") {[name], state}