MCPcopy Create free account
hub / github.com/vercel/examples / sandbox_create

Function sandbox_create

python/vibe-coding-ide/backend/src/agent/tools/sandbox.py:42–198  ·  view source on GitHub ↗

Create a persistent sandbox and remember it for this run. Args: runtime: Optional runtime, e.g. "node22", "python3.13". ports: Optional list of ports to expose (for previews). timeout_ms: Sandbox lifetime timeout in milliseconds. Returns: JSON with sandbox de

(
    ctx: RunContextWrapper[IDEContext],
    runtime: str | None = None,
    ports: list[int] | None = None,
    timeout_ms: int | None = 600_000,
    name: str | None = None,
)

Source from the content-addressed store, hash-verified

40
41@function_tool
42async def sandbox_create(
43 ctx: RunContextWrapper[IDEContext],
44 runtime: str | None = None,
45 ports: list[int] | None = None,
46 timeout_ms: int | None = 600_000,
47 name: str | None = None,
48) -> str:
49 """Create a persistent sandbox and remember it for this run.
50
51 Args:
52 runtime: Optional runtime, e.g. "node22", "python3.13".
53 ports: Optional list of ports to expose (for previews).
54 timeout_ms: Sandbox lifetime timeout in milliseconds.
55 Returns:
56 JSON with sandbox details.
57 """
58 tool_id = f"tc_{len(ctx.context.events) + 1}"
59 args = {"runtime": runtime, "ports": ports, "timeout_ms": timeout_ms, "name": name}
60 ctx.context.events.append(
61 {
62 "phase": "started",
63 "tool_id": tool_id,
64 "name": "sandbox_create",
65 "arguments": args,
66 }
67 )
68
69 sb_name = normalize_sandbox_name(ctx, name)
70
71 # Synthetic runtimes: if a Ruby or Go runtime is requested, create on a Node runtime and bootstrap
72 requested_runtime = runtime
73 is_synthetic_ruby = bool(
74 requested_runtime and str(requested_runtime).lower().startswith("ruby")
75 )
76 is_synthetic_go = bool(
77 requested_runtime and str(requested_runtime).lower().startswith("go")
78 )
79 effective_runtime = requested_runtime
80 if is_synthetic_ruby or is_synthetic_go:
81 # Default to node22 as the base image for bootstrapping
82 effective_runtime = "node22"
83
84 sandbox = await Sandbox.create(
85 timeout=timeout_ms or 600_000,
86 runtime=effective_runtime,
87 ports=ports,
88 )
89 # Map and set active sandbox
90 ctx.context.sandbox_name_to_id[sb_name] = sandbox.sandbox_id
91 ctx.context.active_sandbox = sb_name
92 # Persist preferences per-sandbox
93 if requested_runtime or effective_runtime:
94 ctx.context.sandbox_runtime_map[sb_name] = (
95 requested_runtime or effective_runtime
96 ) # type: ignore[arg-type]
97 if ports is not None:
98 ctx.context.sandbox_ports_map[sb_name] = ports
99

Callers

nothing calls this directly

Calls 9

normalize_sandbox_nameFunction · 0.90
sync_project_filesFunction · 0.90
upsert_user_sandboxFunction · 0.90
_run_allFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected