Skip to content

armgit / janas

Public Imported from GitHub
0

37 tok/s from Qwen3-Next-80B (48 GB) on a 32 GB laptop, 24 without drafts vs 2.8 for llama.cpp; reading 62 vs 16 tok/s. Faster than llama.cpp on all 13 models compared in Q4_K_M. LLMs bigger than your RAM, pure C, CPU or GPU.

2.3 KB
Raw Blame
/* SPDX-License-Identifier: GPL-3.0-or-later
   Copyright (C) 2026 Maurizio Cammalleri */
/*
 * sandbox.h - a cage for programs Janas runs but did not write (the code a
 * model writes for code_interpreter): Linux namespaces of its own (user,
 * mount, PID, network, IPC, UTS) without privileges, a root of its own
 * with the system's /usr read-only and one directory writable, no network,
 * no other process to see, no new processes (seccomp: threads only),
 * limits on memory, file sizes and open files.
 *
 * The cage is built by the program itself run again: janas_sandbox_spawn
 * runs /proc/self/exe with janas_sandbox_exec's first argument, and a
 * program offering the cage calls janas_sandbox_main first thing in main.
 * Linux only (x86-64 and AArch64); elsewhere janas_sandbox_available says
 * why not.
 */
#ifndef JANAS_COMMON_SANDBOX_H
#define JANAS_COMMON_SANDBOX_H

#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>

#define JANAS_SANDBOX_ARG "--janas-sandbox-exec"

struct janas_sandbox_cfg {
    const char *data_dir;  /* host directory, writable at /mnt/data */
    const char *const *ro; /* more host paths, read-only at the same path
                              (NULL-terminated; may be NULL) */
    uint64_t mem_bytes;    /* address space; 0: 2 GiB */
    uint64_t file_bytes;   /* largest file written; 0: 1 GiB */
    uint64_t tmp_bytes;    /* the /tmp in memory; 0: 256 MiB */
};

struct janas_sandbox {
    pid_t pid;        /* the cage's first process */
    int in, out, err; /* its standard input, output and error */
};

/* Whether a cage can be built here: 1, or 0 with the reason. */
int janas_sandbox_available(char *why, size_t n);

/* argv (argv[0] a path inside the cage, as /usr/bin/python3) run in a cage
   with envp as its whole environment: 0 with sb filled, -1 with the
   reason. The cage dies with its caller. */
int janas_sandbox_spawn(const struct janas_sandbox_cfg *c, char *const argv[],
                        char *const envp[], struct janas_sandbox *sb, char *why,
                        size_t n);

/* The cage killed (and its pipes closed). */
void janas_sandbox_kill(struct janas_sandbox *sb);

/* In main, first: when argv[1] is JANAS_SANDBOX_ARG this process is a cage
   being built, and the function never returns; otherwise it returns at
   once. */
void janas_sandbox_main(int argc, char **argv);

#endif