the universal sandbox runtime for agents and humans.
pocketenv.io
sandbox
openclaw
agent
claude-code
vercel-sandbox
deno-sandbox
cloudflare-sandbox
atproto
sprites
daytona
1import { client } from "../client";
2import open from "open";
3import express, { type Request, type Response } from "express";
4import cors from "cors";
5import fs from "node:fs/promises";
6import os from "node:os";
7import path from "node:path";
8import chalk from "chalk";
9
10async function login(handle: string) {
11 const app = express();
12 app.use(cors());
13 app.use(express.json());
14
15 const server = app.listen(6997);
16
17 app.post("/token", async (req: Request, res: Response) => {
18 console.log(chalk.bold(chalk.greenBright("Login successful!\n")));
19 const tokenPath = path.join(os.homedir(), ".pocketenv", "token.json");
20 await fs.mkdir(path.dirname(tokenPath), { recursive: true });
21 await fs.writeFile(
22 tokenPath,
23 JSON.stringify({ token: req.body.token }, null, 2),
24 );
25
26 res.json({
27 ok: 1,
28 });
29
30 server.close();
31 });
32
33 const response = await client.post(`/login`, { handle, cli: true });
34
35 const redirectUrl = response.data;
36
37 if (!redirectUrl.includes("authorize")) {
38 console.error("Failed to login, please check your handle and try again.");
39 server.close();
40 return;
41 }
42
43 console.log("Please visit this URL to authorize the app:");
44 console.log(chalk.cyan(redirectUrl));
45
46 await open(response.data);
47}
48
49export default login;